Namespaces | |
maxon | |
maxon::details | |
Typedefs | |
template<typename T > | |
using | ResultPtr = ResultMemT< T * > |
Enumerations | |
enum class | ERROR_OK { VALUE } |
enum class | ERROR_FAILED { VALUE } |
enum class | ERROR_TYPE { OUT_OF_MEMORY , NULLPTR , ILLEGAL_ARGUMENT , ILLEGAL_STATE , NOT_IMPLEMENTED , UNRESOLVED , UNKNOWN } |
Functions | |
enum maxon::ERROR_OK | MAXON_ENUM_LIST (ERROR_OK) |
enum maxon::ERROR_FAILED | MAXON_ENUM_LIST (ERROR_FAILED) |
enum maxon::ERROR_TYPE | MAXON_ENUM_LIST (ERROR_TYPE) |
const Error * | CreateErrorPtr (MAXON_SOURCE_LOCATION_DECLARATION, ERROR_TYPE type) __attribute__((pure |
ThreadReferencedError | CreateError (MAXON_SOURCE_LOCATION_DECLARATION, ERROR_TYPE type) |
const Error * | PrivateSystemSetCurrentError (const Error &error) |
const Error * | PrivateSystemSetCurrentError (Error &&error) |
void | PrivateSetError (Error &dest, const Error *src) |
MAXON_MEMBERTYPE_DETECTOR (IsForwardRef, IsForwardRef, std::false_type) | |
template<typename T > | |
MAXON_ATTRIBUTE_FORCE_INLINE auto | operator% (const ResultOk< T > &rv, ThreadReferencedError &err) -> decltype(rv.GetValue()) |
template<typename T > | |
MAXON_ATTRIBUTE_FORCE_INLINE T | operator% (ResultOk< T > &&rv, ThreadReferencedError &err) |
template<typename T > | |
MAXON_ATTRIBUTE_FORCE_INLINE T & | operator% (ResultOk< T & > &&rv, ThreadReferencedError &err) |
MAXON_ATTRIBUTE_FORCE_INLINE void | operator% (ResultOk< void > &&rv, ThreadReferencedError &err) |
template<typename T > | |
MAXON_ATTRIBUTE_FORCE_INLINE auto | operator% (const ResultOk< T > &rv, maxon::details::ResultOkError &err) -> decltype(rv.GetValue()) |
template<typename T > | |
MAXON_ATTRIBUTE_FORCE_INLINE T | operator% (ResultOk< T > &&rv, maxon::details::ResultOkError &err) |
template<typename T > | |
MAXON_ATTRIBUTE_FORCE_INLINE T & | operator% (ResultOk< T & > &&rv, maxon::details::ResultOkError &err) |
MAXON_ATTRIBUTE_FORCE_INLINE void | operator% (ResultOk< void > &&rv, maxon::details::ResultOkError &err) |
template<typename T > | |
MAXON_ATTRIBUTE_FORCE_INLINE auto | operator% (const Result< T > &rv, ThreadReferencedError &err) -> decltype(rv.GetValue()) |
template<typename T > | |
MAXON_ATTRIBUTE_FORCE_INLINE T | operator% (Result< T > &&rv, ThreadReferencedError &err) |
template<typename T > | |
MAXON_ATTRIBUTE_FORCE_INLINE T & | operator% (const Result< T & > &rv, ThreadReferencedError &err) |
template<typename T > | |
MAXON_ATTRIBUTE_FORCE_INLINE T & | operator% (Result< T & > &&rv, ThreadReferencedError &err) |
MAXON_ATTRIBUTE_FORCE_INLINE void | operator% (const Result< void > &rv, ThreadReferencedError &err) |
MAXON_ATTRIBUTE_FORCE_INLINE void | operator% (Result< void > &&rv, ThreadReferencedError &err) |
template<typename T > | |
MAXON_ATTRIBUTE_FORCE_INLINE T && | operator% (ResultMemT< T > &&ptr, ThreadReferencedError &err) |
template<typename T > | |
MAXON_ATTRIBUTE_FORCE_INLINE const T & | operator% (const ResultMemT< T > &ptr, ThreadReferencedError &err) |
template<typename T > | |
MAXON_ATTRIBUTE_FORCE_INLINE T & | operator% (ResultRef< T > ptr, ThreadReferencedError &err) |
Variables | |
VALUE | |
static const ERROR_FAILED | FAILED |
OUT_OF_MEMORY | |
NULLPTR | |
ILLEGAL_ARGUMENT | |
ILLEGAL_STATE | |
NOT_IMPLEMENTED | |
UNRESOLVED | |
UNKNOWN | |
const Error | returns_nonnull |
#define PRIVATE_MAXON_RBF_SENTINEL | ( | ... | ) |
#define PRIVATE_MAXON_ENABLE_IF_ERROR | ( | TYPE | ) |
#define PRIVATE_MAXON_ENABLE_IF_ERROR_DUMMY |
#define PRIVATE_MAXON_iferr_scope | ( | T | ) |
#define PRIVATE_MAXON_iferr_scope_handler | ( | ) |
#define PRIVATE_MAXON_iferr_diag_handler0 | ( | errResult, | |
formatString, | |||
... | |||
) |
#define PRIVATE_MAXON_iferr_diag_handler1 | ( | errResult, | |
formatString, | |||
... | |||
) |
#define PRIVATE_MAXON_iferr_diag_handlerc | ( | vaArgsPopulated, | |
errResult, | |||
formatString, | |||
... | |||
) |
#define PRIVATE_MAXON_iferr_diag_handlerb | ( | vaArgsPopulated, | |
errResult, | |||
formatString, | |||
... | |||
) |
#define PRIVATE_MAXON_iferr_diag_handlera | ( | vaArgsPopulated, | |
errResult, | |||
formatString, | |||
... | |||
) |
#define PRIVATE_MAXON_iferr_return | ( | ) |
#define PRIVATE_MAXON_iferr_cannot_fail | ( | str | ) |
#define PRIVATE_MAXON_iferr_ignore | ( | ... | ) |
#define iferr_scope |
Instead of using iferr
you can define an iferr_scope
and within this scope call methods which might return an error (and decorate them with the iferr_return
attribute). If a method returns with an error iferr_return
will forward it.
#define iferr_scope_handler |
To perform a specific action in case of an error (additional logging, or just to set a breakpoint for debugging) you can replace iferr_scope
by an iferr_scope_handler:
iferr_scope_handler implicitely defines the error variable 'err'.
#define iferr_diag_handler | ( | errResult, | |
formatString, | |||
... | |||
) |
Condensed version of iferr_scope_handler. Allows to add some local context to error coming from inner calls (lower level code). The nested error and local context are printed to the console based on g_diagnostic configuration. Can be used on legacy code side of Maxon API code side since the handler's return value is defined by the first argument #errResult. See iferr_scope for details. One per scope only.
[in] | errResult | Value to return in case of error. |
[in] | formatString | Format for the DiagnosticOutput embedded call. Variadic arguments should match the number of '@' in #formatString. err.ToString() will be added automatically at the end of the string. |
#define iferr_cannot_fail | ( | str | ) |
If an error cannot occur (because you've ensured this by preallocating resources or the algorithm was designed in such a way, etc.) you might use iferr_cannot_fail
with a comment which explans why it can't fail. In debug this will check for errors and invoke DebugStop() to notify you that your code is broken, but in release there are no error checks.
#define iferr_ignore | ( | ... | ) |
If for perfomance reasons a piece of code has been very carefully designed in a way that error checking is performed at the very end and that no checks are necessary inbetween you may qualify calls with iferr_ignore
and a comment which describes why the error can be ignored.
#define iferr_scope_result |
Use iferr_scope_result in finally blocks to deallocate resources based on the error state.
#define iferr_return |
The iferr_return macro is the easiest way to introduce error handling. It quickly allows you leave a function as soon as an error occurs. iferr_return requires you to define iferr_scope or iferr_scope_handler once beforehand (preferably at the beginning of your function)
iferr_return forwards the error to the calling function. To do this your function must either return Result<T> or use an iferr_scope_handler.
When iferr_return is used within 'for', 'if', 'else' or 'while' those statements must use brackets around their scope, otherwise iferr_return will not be properly executed.
#define PRIVATE_iferr_throw | ( | VAR, | |
... | |||
) |
#define iferr_throw | ( | ERR | ) |
Manually throw an error. Especially useful in combination with iferr_scope_handler to cleanup things in case of errors. Usually you just create error messages and return them in case of a problem like in this example:
The big problem is that in case of an error the allocated chars are nevers freed. Instead of deleting the mem at each possible error point in the algo you can throw the error instead of returning them and then catch the error with iferr_scope_handler and handle the cleanup at a single place like in this example:
VALUE |
The single value of this enum.
OUT_OF_MEMORY |
Create an OutOfMemoryError.
NULLPTR |
Create a NullptrError.
ILLEGAL_ARGUMENT |
Create an IllegalArgumentError.
ILLEGAL_STATE |
Create an IllegalStateError.
NOT_IMPLEMENTED |
Create a FunctionNotImplementedError.
UNRESOLVED |
Create an UnresolvedError.
UNKNOWN |
< Create an UnknownError.