GeoGen API Reference
Handling compilation and runtime errors

This tutorial demonstrates how to handle compilation and runtime errors.

All errors cause an exception to be thrown and can be handled using the usual try - catch statements. Generally, the compiler::Compiler throws exceptions that are subclasses of compiler::CompilerException with error codes 1xxx and the runtime::VirtualMachine throws exceptions that are subclasses of runtime::RuntimeException with error codes 2xxx. Additionally, more generic exceptions such as InternalErrorException and ApiUsageException may be thrown by almost any call, indicating severe error in the generator itself or in the hosting application.

string code = "yield HeightMap.Flat(1 / 0)";
// Create instance of the compiler.
compiler::Compiler compiler;
// All compilation exceptions extend compiler::CompilerException.
runtime::CompiledScript* compiledScript;
try
{
compiledScript = compiler.CompileScript(code);
}
catch (compiler::CompilerException& ex)
{
cout << "Error GGE" << ex.GetErrorCode() << ": " << ex.GetDetailMessage() << endl;
return;
}
// All simulation exceptions extend runtime::RuntimeException.
runtime::VirtualMachine vm(*compiledScript);
try
{
vm.Run();
}
catch (runtime::RuntimeException& ex)
{
cout << "Error GGE" << ex.GetErrorCode() << ": " << ex.GetDetailMessage() << endl;
return;
}
// All renderer exceptions extend renderer::RendererException.
try
{
renderer::Renderer renderer(vm.GetRenderingSequence());
renderer.Run();
genlib::HeightMap* heightMap = renderer.GetRenderedMapTable().GetItem(renderer::Renderer::MAP_NAME_MAIN);
}
catch (runtime::RuntimeException& ex)
{
cout << "Error GGE" << ex.GetErrorCode() << ": " << ex.GetDetailMessage() << endl;
return;
}
// Alternatively, all GeoGen exceptions can be handled by catching GeoGenException.
cout << "Finished!" << endl;

Full code

If an exception is thrown during runtime of the runtime::VirtualMachine the machine will enter faulted state which will block any further execution calls such as runtime::VirtualMachine::Run and runtime::VirtualMachine::Step. Information gathering calls such as runtime::VirtualMachine::GetObjectStack will still work though.