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:155
Member Variables
- private llvm::ErrorInfoBase* Payload = nullptr
Method Overview
- protected Error()
- public Error(const llvm::Error & Other)
- public Error(llvm::Error && Other)
- public Error(std::unique_ptr<ErrorInfoBase> Payload)
- private void assertIsChecked()
- public const void * dynamicClassID() const
- private bool getChecked() const
- private llvm::ErrorInfoBase * getPtr() const
- public template <typename ErrT>bool isA() const
- public bool operator bool()
- private void setChecked(bool V)
- private void setPtr(llvm::ErrorInfoBase * EI)
- public static llvm::ErrorSuccess success()
- private std::unique_ptr<ErrorInfoBase> takePayload()
- public ~Error()
Methods
¶Error()
Error()
Description
Create a success value. Prefer using 'Error::success()' for readability
Declared at: llvm/include/llvm/Support/Error.h:174
¶Error(const llvm::Error& Other)
Error(const llvm::Error& Other)
Declared at: llvm/include/llvm/Support/Error.h:184
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:189
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:196
Parameters
- std::unique_ptr<ErrorInfoBase> Payload
¶void assertIsChecked()
void assertIsChecked()
Declared at: llvm/include/llvm/Support/Error.h:261
¶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:245
¶bool getChecked() const
bool getChecked() const
Declared at: llvm/include/llvm/Support/Error.h:289
¶llvm::ErrorInfoBase* getPtr() const
llvm::ErrorInfoBase* getPtr() const
Declared at: llvm/include/llvm/Support/Error.h:268
¶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:239
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:233
¶void setChecked(bool V)
void setChecked(bool V)
Declared at: llvm/include/llvm/Support/Error.h:297
Parameters
- bool V
¶void setPtr(llvm::ErrorInfoBase* EI)
void setPtr(llvm::ErrorInfoBase* EI)
Declared at: llvm/include/llvm/Support/Error.h:278
Parameters
¶static llvm::ErrorSuccess success()
static llvm::ErrorSuccess success()
Description
Create a success value.
Declared at: llvm/include/llvm/Support/Error.h:181
¶std::unique_ptr<ErrorInfoBase> takePayload()
std::unique_ptr<ErrorInfoBase> takePayload()
Declared at: llvm/include/llvm/Support/Error.h:306
¶~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:225