class Error
Declaration
class Error { /* full declaration omitted */ };
Description
Lightweight error class with error context and mandatory checking. Instances of this class wrap a ErrorInfoBase pointer. Failure states are represented by setting the pointer to a ErrorInfoBase subclass instance containing information describing the failure. Success is represented by a null pointer value. Instances of Error also contains a 'Checked' flag, which must be set before the destructor is called, otherwise the destructor will trigger a runtime error. This enforces at runtime the requirement that all Error instances be checked or returned to the caller. There are two ways to set the checked flag, depending on what state the Error instance is in. For Error instances indicating success, it is sufficient to invoke the boolean conversion operator. E.g.: A success value *can not* be dropped. For example, just calling 'foo( < ...>)' without testing the return value will raise a runtime error, even if foo returns success. For Error instances representing failure, you must use either the handleErrors or handleAllErrors function with a typed handler. E.g.: The handleAllErrors function is identical to handleErrors, except that it has a void return type, and requires all errors to be handled and no new errors be returned. It prevents errors (assuming they can all be handled) from having to be bubbled all the way to the top-level. *All* Error instances must be checked before destruction, even if they're moved-assigned or constructed from Success values that have already been checked. This enforces checking through all levels of the call stack.
Declared at: llvm/include/llvm/Support/Error.h:157
Method Overview
- protected Error()
- public Error(const llvm::Error & Other)
- public Error(llvm::Error && Other)
- public Error(std::unique_ptr<ErrorInfoBase> Payload)
- public const void * dynamicClassID() const
- public template <typename ErrT>bool isA() const
- public bool operator bool()
- public static llvm::ErrorSuccess success()
- public ~Error()
Methods
¶Error()
Error()
Description
Create a success value. Prefer using 'Error::success()' for readability
Declared at: llvm/include/llvm/Support/Error.h:176
¶Error(const llvm::Error& Other)
Error(const llvm::Error& Other)
Declared at: llvm/include/llvm/Support/Error.h:186
Parameters
- const llvm::Error& Other
¶Error(llvm::Error&& Other)
Error(llvm::Error&& Other)
Description
Move-construct an error value. The newly constructed error is considered unchecked, even if the source error had been checked. The original error becomes a checked Success value, regardless of its original state.
Declared at: llvm/include/llvm/Support/Error.h:191
Parameters
- llvm::Error&& Other
¶Error(std::unique_ptr<ErrorInfoBase> Payload)
Error(std::unique_ptr<ErrorInfoBase> Payload)
Description
Create an error value. Prefer using the 'make_error' function, but this constructor can be useful when "re-throwing" errors from handlers.
Declared at: llvm/include/llvm/Support/Error.h:198
Parameters
- std::unique_ptr<ErrorInfoBase> Payload
¶const void* dynamicClassID() const
const void* dynamicClassID() const
Description
Returns the dynamic class id of this error, or null if this is a success value.
Declared at: llvm/include/llvm/Support/Error.h:247
¶template <typename ErrT>
bool isA() const
template <typename ErrT>
bool isA() const
Description
Check whether one error is a subclass of another.
Declared at: llvm/include/llvm/Support/Error.h:241
Templates
- ErrT
¶bool operator bool()
bool operator bool()
Description
Bool conversion. Returns true if this Error is in a failure state, and false if it is in an accept state. If the error is in a Success state it will be considered checked.
Declared at: llvm/include/llvm/Support/Error.h:235
¶static llvm::ErrorSuccess success()
static llvm::ErrorSuccess success()
Description
Create a success value.
Declared at: llvm/include/llvm/Support/Error.h:183
¶~Error()
~Error()
Description
Destroy a Error. Fails with a call to abort() if the error is unchecked.
Declared at: llvm/include/llvm/Support/Error.h:227