# Error handling

Simplygon API reports errors through the error handling class ErrorHandler. A user can derive a class from ErrorHandler, which then will receive processing errors, and handle them appropriately. In C# and Python, if no error handler is set, the errors are reported through exception handling.

This example shows how to use the Simplygon error handler.

// Copyright (c) Microsoft Corporation. 
// Licensed under the MIT license. 

#include <string>
#include <stdlib.h>
#include <filesystem>
#include <future>
#include "SimplygonLoader.h"

class CustomErrorHandler : public Simplygon::ErrorHandler
{
	public:
	void HandleError(Simplygon::spObject object, const char* interfaceName, const char* methodName, Simplygon::rid errorType , const char* errorText) override
	{
		printf("Error (%s:%s): %s\n", interfaceName, methodName, errorText);
	}
} customErrorHandler;


void RunReduction(Simplygon::ISimplygon* sg)
{
	// Set the custom error handler to the Simplygon interface. 
	sg->SetErrorHandler(&customErrorHandler);

	// Create the reduction pipeline. 
	Simplygon::spReductionPipeline sgReductionPipeline = sg->CreateReductionPipeline();

	// To be able to use the T-Junction remover, the welder has to be enabled so this will trigger an 
	// error. 
	Simplygon::spRepairSettings sgRepairSettings = sgReductionPipeline->GetRepairSettings();

	sgRepairSettings->SetUseWelding( false );

	sgRepairSettings->SetUseTJunctionRemover( true );

	// Start the reduction pipeline and the faulty settings will cause an error. 
	sgReductionPipeline->RunSceneFromFile("../Assets/SimplygonMan/SimplygonMan.obj", "output.fbx", Simplygon::EPipelineRunMode::RunInNewProcess);

}

int main()
{
	Simplygon::ISimplygon* sg = NULL;
	Simplygon::EErrorCodes initval = Simplygon::Initialize( &sg );
	if( initval != Simplygon::EErrorCodes::NoError )
	{
		return int(initval);
	}

	RunReduction(sg);

	Simplygon::Deinitialize(sg);

	return 0;
}