About
For different situations different error classes exist. These different classes help to identify the nature of the error and allow to store additional information.
Built-in Types
The default error types are defined in the core.framework.
- Note
- In other frameworks various specialized error types exist.
-
To check the type of a given error one can use maxon::IsErrorOfType().
Errors about incorrect function arguments:
Errors about incorrect function implementations:
Errors about incorrect program flow:
Specialised Errors:
General Errors:
{
{
if (number >= 0)
{
}
else
{
}
}
if (agg.GetCount())
return agg;
}
{
const maxon::Error error = res.
GetError();
{
for (const maxon::Error subError : agg)
{
}
}
}
Custom Error
All error types are based on maxon::ErrorInterface. It is possible to create custom error types based on that interface. See also Interface Basics.
A custom error interfaces is based on the maxon::ErrorInterface (see Error Class):
{
public:
{
*static_cast<typename S::DirectlyReferencedType::Hxx1::ReferenceClass*>(this) = S::DirectlyReferencedType::Hxx1::ErrObj::GetInstance()();
typename S::DirectlyReferencedType::Ptr e = this->MakeWritable(false).GetPointer();
e.SetCustomErrorCode(errorCode);
}
);
};
The registration or implementation of the custom error type can be simplified with these macros:
- ::MAXON_ERROR_REGISTERX: Registers the implementation and publishes the error object.
- MAXON_ERROR_IMPLEMENT_AND_REGISTER: Implements and registers a whole error interface that does not introduce additional methods.
class ExampleErrorImpl :
public maxon::Component<ExampleErrorImpl, ExampleErrorInterface>
{
public:
{
_errorCode =
src._errorCode;
}
public:
{
}
{
_errorCode = errorCode;
}
{
return _errorCode;
}
private:
};
The new error type can now easily be used:
Further Reading