LLVM  4.0.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
llvm::Error Class Reference

Lightweight error class with error context and mandatory checking. More...

#include <Error.h>

Inheritance diagram for llvm::Error:
[legend]

Public Member Functions

 Error (const Error &Other)=delete
 
 Error (Error &&Other)
 Move-construct an error value. More...
 
 Error (std::unique_ptr< ErrorInfoBase > Payload)
 Create an error value. More...
 
Erroroperator= (const Error &Other)=delete
 
Erroroperator= (Error &&Other)
 Move-assign an error value. More...
 
 ~Error ()
 Destroy a Error. More...
 
 operator bool ()
 Bool conversion. More...
 
template<typename ErrT >
bool isA () const
 Check whether one error is a subclass of another. More...
 

Static Public Member Functions

static ErrorSuccess success ()
 Create a success value. More...
 

Protected Member Functions

 Error ()
 Create a success value. Prefer using 'Error::success()' for readability. More...
 

Friends

class ErrorList
 
template<typename T >
class Expected
 
template<typename... HandlerTs>
Error handleErrors (Error E, HandlerTs &&...Handlers)
 Pass the ErrorInfo(s) contained in E to their respective handlers. More...
 

Detailed 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.:

Error foo(<...>);
if (auto E = foo(<...>))
return E; // <- Return E if it is in the error state.
// We have verified that E was in the success state. It can now be safely
// destroyed.

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.:

class MyErrorInfo : public ErrorInfo<MyErrorInfo> {
// Custom error info.
};
Error foo(<...>) { return make_error<MyErrorInfo>(...); }
auto E = foo(<...>); // <- foo returns failure with MyErrorInfo.
auto NewE =
[](const MyErrorInfo &M) {
// Deal with the error.
},
[](std::unique_ptr<OtherError> M) -> Error {
if (canHandle(*M)) {
// handle error.
return Error::success();
}
// Couldn't handle this error instance. Pass it up the stack.
return Error(std::move(M));
);
// Note - we must check or return NewE in case any of the handlers
// returned a new error.

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.

Definition at line 152 of file Support/Error.h.

Constructor & Destructor Documentation

llvm::Error::Error ( )
inlineprotected

Create a success value. Prefer using 'Error::success()' for readability.

Definition at line 167 of file Support/Error.h.

llvm::Error::Error ( const Error Other)
delete
llvm::Error::Error ( Error &&  Other)
inline

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.

Definition at line 182 of file Support/Error.h.

References Other.

llvm::Error::Error ( std::unique_ptr< ErrorInfoBase Payload)
inline

Create an error value.

Prefer using the 'make_error' function, but this constructor can be useful when "re-throwing" errors from handlers.

Definition at line 189 of file Support/Error.h.

llvm::Error::~Error ( )
inline

Destroy a Error.

Fails with a call to abort() if the error is unchecked.

Definition at line 218 of file Support/Error.h.

References getPtr().

Member Function Documentation

template<typename ErrT >
bool llvm::Error::isA ( ) const
inline

Check whether one error is a subclass of another.

Definition at line 232 of file Support/Error.h.

References getPtr().

llvm::Error::operator bool ( )
inlineexplicit

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.

Definition at line 226 of file Support/Error.h.

References getPtr().

Error& llvm::Error::operator= ( const Error Other)
delete
Error& llvm::Error::operator= ( Error &&  Other)
inline

Move-assign an error value.

The current error must represent success, you you cannot overwrite an unhandled error. The current error is then considered unchecked. The source error becomes a checked success value, regardless of its original state.

Definition at line 201 of file Support/Error.h.

References Other.

ErrorSuccess llvm::Error::success ( )
inlinestatic

Create a success value.

Definition at line 299 of file Support/Error.h.

Referenced by llvm::lto::LTO::add(), llvm::pdb::DbiStreamBuilder::addDbgStream(), llvm::pdb::DbiStreamBuilder::addModuleInfo(), llvm::pdb::DbiStreamBuilder::addModuleSourceFile(), llvm::lto::Config::addSaveTemps(), llvm::orc::rpc::detail::RPCEndpointBase< SingleThreadedRPCEndpoint< ChannelT, FunctionIdT, SequenceNumberT >, ChannelT, FunctionIdT, SequenceNumberT >::appendCallAsync(), llvm::orc::rpc::MultiThreadedRPCEndpoint< ChannelT, FunctionIdT, SequenceNumberT >::appendCallNB(), llvm::ErrorHandlerTraits< void(&)(ErrT &)>::apply(), llvm::ErrorHandlerTraits< void(&)(std::unique_ptr< ErrT >)>::apply(), llvm::object::Archive::Archive(), llvm::lto::backend(), llvm::codeview::CodeViewRecordIO::beginRecord(), llvm::orc::rpc::SingleThreadedRPCEndpoint< rpc::RawByteChannel >::callB(), checkDyldCommand(), checkDyldInfoCommand(), checkDylibCommand(), checkDylibIdCommand(), checkDysymtabCommand(), checkEncryptCommand(), llvm::pdb::checkHashHdrVersion(), checkLinkeditDataCommand(), checkLinkerOptCommand(), checkOverlappingElement(), checkRpathCommand(), checkSubCommand(), llvm::object::MachOObjectFile::checkSymbolTable(), checkSymtabCommand(), checkThreadCommand(), checkTwoLevelHintsCommand(), checkVersCommand(), llvm::collectPGOFuncNameStrings(), llvm::pdb::GlobalsStream::commit(), llvm::pdb::SymbolStream::commit(), llvm::pdb::NameMapBuilder::commit(), llvm::pdb::ModStream::commit(), llvm::pdb::PublicsStream::commit(), llvm::pdb::TpiStream::commit(), llvm::pdb::TpiStreamBuilder::commit(), llvm::pdb::DbiStreamBuilder::commit(), llvm::msf::MutableByteStream::commit(), llvm::RuntimeDyldImpl::computeTotalAllocSize(), llvm::codeview::consume(), llvm::codeview::consume_numeric(), llvm::orc::rpc::SequenceTraits< ChannelT >::consumeSeparator(), llvm::object::MachOUniversalBinary::create(), llvm::coverage::BinaryCoverageReader::create(), llvm::object::MachOObjectFile::create(), llvm::object::Archive::create(), llvm::InstrProfSymtab::create(), llvm::orc::remote::OrcRemoteTargetClient< ChannelT >::Create(), llvm::pdb::DIASession::createFromExe(), llvm::pdb::DIASession::createFromPdb(), llvm::pdb::RawSession::createFromPdb(), llvm::orc::remote::OrcRemoteTargetClient< ChannelT >::createIndirectStubsManager(), llvm::orc::remote::OrcRemoteTargetClient< ChannelT >::createRemoteMemoryManager(), llvm::orc::LocalIndirectStubsManager< TargetT >::createStub(), llvm::orc::LocalIndirectStubsManager< TargetT >::createStubs(), llvm::orc::remote::OrcRemoteTargetClient< ChannelT >::RCIndirectStubsManager::createStubs(), llvm::object::ObjectFile::createWasmObjectFile(), llvm::object::Decompressor::decompress(), llvm::codeview::serialize_conditional_impl< T, U >::deserialize(), llvm::orc::rpc::SerializationTraits< ChannelT, T, T, typename std::enable_if< std::is_base_of< RawByteChannel, ChannelT >::value &&(std::is_same< T, uint8_t >::value||std::is_same< T, int8_t >::value||std::is_same< T, uint16_t >::value||std::is_same< T, int16_t >::value||std::is_same< T, uint32_t >::value||std::is_same< T, int32_t >::value||std::is_same< T, uint64_t >::value||std::is_same< T, int64_t >::value||std::is_same< T, char >::value)>::type >::deserialize(), llvm::codeview::serialize_vector_tail_impl< T >::deserialize(), llvm::orc::rpc::SequenceSerialization< ChannelT >::deserialize(), llvm::orc::rpc::SerializationTraits< ChannelT, std::vector< T > >::deserialize(), llvm::codeview::CVTypeDumper::dump(), llvm::RuntimeDyldImpl::emitCommonSymbols(), llvm::orc::OrcAArch64::emitIndirectStubsBlock(), llvm::orc::OrcX86_64_Base::emitIndirectStubsBlock(), llvm::orc::OrcI386::emitIndirectStubsBlock(), llvm::orc::rpc::SequenceTraits< ChannelT >::emitSeparator(), llvm::orc::rpc::RawByteChannel::endReceiveMessage(), llvm::codeview::CodeViewRecordIO::endRecord(), llvm::orc::rpc::RawByteChannel::endSendMessage(), llvm::InstrProfReader::error(), llvm::errorCodeToError(), llvm::RuntimeDyldMachOCRTPBase< Impl >::finalizeLoad(), llvm::RuntimeDyldELF::finalizeLoad(), llvm::RuntimeDyldCOFFX86_64::finalizeLoad(), llvm::RuntimeDyldImpl::finalizeLoad(), llvm::pdb::InfoStreamBuilder::finalizeMsfLayout(), llvm::pdb::TpiStreamBuilder::finalizeMsfLayout(), llvm::pdb::DbiStreamBuilder::finalizeMsfLayout(), llvm::RuntimeDyldMachOX86_64::finalizeSection(), llvm::RuntimeDyldMachOI386::finalizeSection(), llvm::RuntimeDyldMachOARM::finalizeSection(), llvm::RuntimeDyldMachOAArch64::finalizeSection(), llvm::InstrProfReader::getError(), llvm::coverage::CovMapFunctionRecordV1< IntPtrT >::getFuncName(), llvm::coverage::CovMapFunctionRecord::getFuncName(), llvm::object::Archive::Symbol::getMember(), llvm::object::Archive::Child::getNext(), llvm::getOffset(), llvm::InstrProfReaderIndex< HashTableImpl >::getRecords(), llvm::handleErrors(), llvm::orc::rpc::detail::ResponseHandlerImpl< ChannelT, void, HandlerT >::handleResponse(), llvm::orc::rpc::detail::RPCEndpointBase< SingleThreadedRPCEndpoint< ChannelT, FunctionIdT, SequenceNumberT >, ChannelT, FunctionIdT, SequenceNumberT >::handleResponse(), llvm::orc::rpc::MultiThreadedRPCEndpoint< ChannelT, FunctionIdT, SequenceNumberT >::handlerLoop(), llvm::pdb::ModInfo::initialize(), llvm::pdb::PDBFileBuilder::initialize(), llvm::codeview::ModuleSubstream::initialize(), llvm::object::isNotObjectErrorInvalidFileType(), llvm::pdb::NameMap::load(), llvm::pdb::NameHashTable::load(), loadBinaryFormat(), LoadDIA(), loadSectionContribs(), loadTestingFormat(), llvm::object::MachOUniversalBinary::MachOUniversalBinary(), llvm::codeview::CodeViewRecordIO::mapByteVectorTail(), llvm::codeview::CodeViewRecordIO::mapEncodedInteger(), llvm::codeview::CodeViewRecordIO::mapEnum(), llvm::codeview::CodeViewRecordIO::mapGuid(), llvm::codeview::CodeViewRecordIO::mapInteger(), mapLocalVariableAddrRange(), mapNameAndUniqueName(), llvm::codeview::CodeViewRecordIO::mapObject(), llvm::codeview::CodeViewRecordIO::mapStringZ(), llvm::codeview::CodeViewRecordIO::mapStringZVectorZ(), llvm::codeview::CodeViewRecordIO::mapVectorN(), llvm::codeview::CodeViewRecordIO::mapVectorTail(), llvm::Module::materialize(), llvm::Module::materializeAll(), llvm::Module::materializeMetadata(), llvm::InstrProfWriter::mergeRecordsFromWriter(), NaiveLogLoader(), llvm::orc::rpc::APICalls< Funcs >::negotiate(), llvm::orc::rpc::MultiThreadedRPCEndpoint< ChannelT, FunctionIdT, SequenceNumberT >::negotiateFunction(), llvm::orc::rpc::SingleThreadedRPCEndpoint< rpc::RawByteChannel >::negotiateFunction(), llvm::msf::VarStreamArrayExtractor< codeview::CVRecord< Kind > >::operator()(), llvm::msf::VarStreamArrayExtractor< pdb::ModInfo >::operator()(), llvm::msf::VarStreamArrayExtractor< codeview::ModuleSubstream >::operator()(), llvm::msf::VarStreamArrayExtractor< codeview::LineColumnEntry >::operator()(), llvm::msf::VarStreamArrayExtractor< codeview::FileChecksumEntry >::operator()(), llvm::orc::rpc::detail::ReadArgs< ArgTs...>::operator()(), llvm::pdb::PDBFile::parseFileHeaders(), parseSegmentLoadCommand(), llvm::pdb::PDBFile::parseStreamData(), llvm::RuntimeDyldMachO::populateIndirectSymbolPointersSection(), llvm::coverage::RawCoverageFilenamesReader::read(), llvm::coverage::RawCoverageMappingReader::read(), llvm::msf::StreamReader::readArray(), llvm::msf::StreamReader::readBytes(), llvm::msf::ByteStream::readBytes(), llvm::msf::SequencedItemStream< codeview::CVType >::readBytes(), llvm::msf::MappedBlockStream::readBytes(), readCoverageMappingData(), llvm::msf::StreamReader::readEnum(), llvm::msf::StreamReader::readFixedString(), llvm::pdb::readGSIHashBuckets(), llvm::pdb::readGSIHashHeader(), llvm::pdb::readGSIHashRecords(), llvm::msf::StreamReader::readInteger(), llvm::coverage::RawCoverageReader::readIntMax(), llvm::msf::StreamReader::readLongestContiguousChunk(), llvm::msf::ByteStream::readLongestContiguousChunk(), llvm::msf::SequencedItemStream< codeview::CVType >::readLongestContiguousChunk(), llvm::msf::MappedBlockStream::readLongestContiguousChunk(), llvm::msf::ReadableStreamRef::readLongestContiguousChunk(), llvm::coverage::BinaryCoverageReader::readNextRecord(), llvm::msf::StreamReader::readObject(), llvm::readPGOFuncNameStrings(), llvm::coverage::RawCoverageReader::readSize(), llvm::msf::StreamReader::readStreamRef(), llvm::coverage::RawCoverageReader::readString(), llvm::coverage::RawCoverageReader::readULEB128(), llvm::msf::StreamReader::readZeroString(), llvm::pdb::SymbolStream::reload(), llvm::pdb::ModStream::reload(), llvm::pdb::PublicsStream::reload(), llvm::pdb::GlobalsStream::reload(), llvm::pdb::TpiStream::reload(), llvm::pdb::DbiStream::reload(), llvm::orc::rpc::detail::HandlerTraits< RetT(ArgTs...)>::run(), llvm::orc::rpc::SequenceSerialization< ChannelT >::serialize(), llvm::orc::rpc::SerializationTraits< ChannelT, std::vector< T > >::serialize(), llvm::msf::MSFBuilder::setBlockMapAddr(), llvm::msf::MSFBuilder::setDirectoryBlocksHint(), llvm::InstrProfWriter::setIsIRLevelProfile(), llvm::msf::MSFBuilder::setStreamSize(), llvm::msf::StreamReader::skip(), llvm::codeview::CodeViewRecordIO::skipPadding(), llvm::SoftInstrProfErrors::takeError(), llvm::Expected< T >::takeError(), takeObject(), llvm::lto::thinBackend(), llvm::orc::LocalIndirectStubsManager< TargetT >::updatePointer(), llvm::msf::validateSuperBlock(), llvm::codeview::CVTypeVisitor::visitFieldListMemberStream(), visitKnownMember(), visitKnownRecord(), llvm::pdb::TpiHashVerifier::visitKnownRecord(), llvm::codeview::TypeDatabaseVisitor::visitMemberBegin(), llvm::codeview::TypeRecordMapping::visitMemberBegin(), llvm::codeview::TypeVisitorCallbacks::visitMemberBegin(), llvm::codeview::TypeDumpVisitor::visitMemberBegin(), llvm::codeview::TypeVisitorCallbackPipeline::visitMemberBegin(), llvm::codeview::TypeSerializer::visitMemberBegin(), llvm::codeview::TypeDatabaseVisitor::visitMemberEnd(), llvm::codeview::TypeRecordMapping::visitMemberEnd(), llvm::codeview::TypeVisitorCallbacks::visitMemberEnd(), llvm::codeview::TypeDumpVisitor::visitMemberEnd(), llvm::codeview::TypeVisitorCallbackPipeline::visitMemberEnd(), llvm::codeview::TypeSerializer::visitMemberEnd(), llvm::codeview::FieldListDeserializer::visitMemberEnd(), visitMemberRecord(), llvm::codeview::SymbolRecordMapping::visitSymbolBegin(), llvm::codeview::SymbolVisitorCallbackPipeline::visitSymbolBegin(), llvm::codeview::SymbolVisitorCallbacks::visitSymbolBegin(), llvm::codeview::SymbolSerializer::visitSymbolBegin(), llvm::codeview::SymbolRecordMapping::visitSymbolEnd(), llvm::codeview::SymbolVisitorCallbacks::visitSymbolEnd(), llvm::codeview::SymbolVisitorCallbackPipeline::visitSymbolEnd(), llvm::codeview::SymbolSerializer::visitSymbolEnd(), llvm::codeview::CVSymbolVisitor::visitSymbolRecord(), llvm::codeview::CVSymbolVisitor::visitSymbolStream(), llvm::codeview::TypeDatabaseVisitor::visitTypeBegin(), llvm::codeview::TypeRecordMapping::visitTypeBegin(), llvm::codeview::TypeVisitorCallbacks::visitTypeBegin(), llvm::codeview::TypeDumpVisitor::visitTypeBegin(), llvm::codeview::TypeVisitorCallbackPipeline::visitTypeBegin(), llvm::pdb::TpiHashVerifier::visitTypeBegin(), llvm::codeview::TypeSerializer::visitTypeBegin(), llvm::codeview::TypeDatabaseVisitor::visitTypeEnd(), llvm::codeview::TypeRecordMapping::visitTypeEnd(), llvm::codeview::TypeVisitorCallbacks::visitTypeEnd(), llvm::codeview::TypeDumpVisitor::visitTypeEnd(), llvm::codeview::TypeVisitorCallbackPipeline::visitTypeEnd(), llvm::codeview::TypeSerializer::visitTypeEnd(), llvm::codeview::CVTypeVisitor::visitTypeRecord(), llvm::codeview::CVTypeVisitor::visitTypeStream(), llvm::codeview::TypeVisitorCallbacks::visitUnknownMember(), llvm::codeview::TypeVisitorCallbackPipeline::visitUnknownMember(), llvm::codeview::TypeDumpVisitor::visitUnknownMember(), llvm::codeview::SymbolVisitorCallbackPipeline::visitUnknownSymbol(), llvm::codeview::SymbolVisitorCallbacks::visitUnknownSymbol(), llvm::codeview::TypeVisitorCallbacks::visitUnknownType(), llvm::codeview::TypeVisitorCallbackPipeline::visitUnknownType(), llvm::codeview::TypeDumpVisitor::visitUnknownType(), llvm::orc::rpc::ParallelCallGroup< RPCClass >::wait(), llvm::msf::StreamWriter::writeArray(), llvm::msf::StreamWriter::writeBytes(), llvm::msf::MutableByteStream::writeBytes(), llvm::msf::WritableMappedBlockStream::writeBytes(), llvm::msf::StreamWriter::writeFixedString(), llvm::msf::StreamWriter::writeStreamRef(), llvm::msf::StreamWriter::writeZeroString(), YAMLLogLoader(), and llvm::ErrorAsOutParameter::~ErrorAsOutParameter().

Friends And Related Function Documentation

friend class ErrorList
friend

Definition at line 155 of file Support/Error.h.

template<typename T >
friend class Expected
friend

Definition at line 163 of file Support/Error.h.

template<typename... HandlerTs>
Error handleErrors ( Error  E,
HandlerTs &&...  Handlers 
)
friend

Pass the ErrorInfo(s) contained in E to their respective handlers.

Any unhandled errors (or Errors returned by handlers) are re-concatenated and returned. Because this function returns an error, its result must also be checked or returned. If you intend to handle all errors use handleAllErrors (which returns void, and will abort() on unhandled errors) instead.

Definition at line 518 of file Support/Error.h.


The documentation for this class was generated from the following file: