Error Class

内容表

关于

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 接口基础 .

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 err.DiagOutput(); }

延伸阅读

maxon::String
定义: string.h:1197
maxon::OK
return OK
定义: apibase.h:2532
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
maxon::SourceLocation::file
const Char * file
定义: memoryallocationbase.h:20
maxon::Result
定义: apibase.h:314
maxon::SourceLocation
定义: memoryallocationbase.h:17
maxon::FAILED
static const ERROR_FAILED FAILED
定义: resultbase.h:68
maxon::Result::GetError
const Error & GetError() const
定义: resultbase.h:1026
iferr
#define iferr(...)
定义: errorbase.h:380

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1