Error Class

Table of Contents


All error types of the MAXON API are based on the maxon::ErrorInterface. This interface defines functions to set and get the information stored in the error object.

For creating new error types based on this interface see Error Types and Interface Basics.

Error Class

Basic information stored in an error object is accessed with:

The following data may or may not be set, depending on the error:

// This example gets the error from the maxon::Result object and prints it in a custom way.
const maxon::Result<maxon::Int> res = GetRandomNumber();
if (res == maxon::FAILED)
const maxon::Error error = res.GetError();
// get info on the error
const maxon::String message = error.GetMessage();
const maxon::SourceLocation location = error.GetLocation();
const maxon::String file(location.file);
// print
DiagnosticOutput("Error \"@\" in file @", message, file);

Additionally, error objects provide these functions:

// This example calls a sub-function and returns an UnexpectedError in case of an failure.
// If an error is returned, a debug stop is triggered.
static maxon::Result<void> CallAction()
if (Action() == false)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "Could not perform action."_s).DbgStop();
return maxon::OK;
// This example calls a function that may fail.
// If an error occurred, the error is printed to the console.
iferr (CallAction())
// print error

Further Reading