Error Result
The error reporting system of the MAXON API is based on the maxon::Result template. Such a maxon::Result object can contain both the actual return value of the function and an error object if an error had occurred.
These default error values are used to check if a maxon::Result object contains an error or not:
//---------------------------------------------------------------------------------------- // Increments the given maxon::Int value. // Returns an NullptrError if an invalid argument is given. // @param[in,out] number Pointer to an maxon::Int value. // @return OK on success. //---------------------------------------------------------------------------------------- static maxon::Result<void> IncrementValue( maxon::Int * const number) { if (number == nullptr ) return maxon::NullptrError( MAXON_SOURCE_LOCATION );
A maxon::ResultBase / maxon::Result object stores the return value and the error returned by a function.
The stored value and error are accessed with:
// if everything is OK, just print the return value if (res == maxon::OK ) { const maxon::Int number = res.GetValue(); DiagnosticOutput ( "Number: @" , number); }
// if some error occurred, print the error if (res == maxon::FAILED ) { const maxon::Error error = res. GetError (); const maxon::String errorMessage = error.GetMessage(); DiagnosticOutput ( "Error: @" , errorMessage); }
For special situations these specialized return values exist: