Error Class

Table of Contents

About

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();
{
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);
}
Definition: resultbase.h:766
Definition: memoryallocationbase.h:18
const Char * file
Definition: memoryallocationbase.h:20
Definition: string.h:1237
PyObject * error
Definition: codecs.h:206
const char * message
Definition: pyerrors.h:189
Py_UCS4 * res
Definition: unicodeobject.h:1113
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:170
static const ERROR_FAILED FAILED
Definition: resultbase.h:68
const char const char const char * file
Definition: object.h:439

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;
}
return OK
Definition: apibase.h:2735
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
// This example calls a function that may fail.
// If an error occurred, the error is printed to the console.
iferr (CallAction())
{
// print error
err.DiagOutput();
}
#define iferr(...)
Definition: errorbase.h:388

Further Reading