LLVM 20.0.0git
Public Member Functions | Static Public Attributes | List of all members
llvm::StringError Class Reference

This class wraps a string in an Error. More...

#include "llvm/Support/Error.h"

Inheritance diagram for llvm::StringError:
Inheritance graph
[legend]

Public Member Functions

 StringError (std::string &&S, std::error_code EC, bool PrintMsgOnly)
 
 StringError (std::error_code EC, const Twine &S=Twine())
 Prints EC + S and converts to EC.
 
 StringError (const Twine &S, std::error_code EC)
 Prints S and converts to EC.
 
void log (raw_ostream &OS) const override
 Print an error message to an output stream.
 
std::error_code convertToErrorCode () const override
 Convert this error to a std::error_code.
 
const std::string & getMessage () const
 
- Public Member Functions inherited from llvm::ErrorInfo< StringError >
const void * dynamicClassID () const override
 
bool isA (const void *const ClassID) const override
 
- Public Member Functions inherited from llvm::ErrorInfoBase
virtual ~ErrorInfoBase ()=default
 
virtual void log (raw_ostream &OS) const =0
 Print an error message to an output stream.
 
virtual std::string message () const
 Return the error message as a string.
 
virtual std::error_code convertToErrorCode () const =0
 Convert this error to a std::error_code.
 
virtual const void * dynamicClassID () const =0
 
virtual bool isA (const void *const ClassID) const
 
template<typename ErrorInfoT >
bool isA () const
 

Static Public Attributes

static char ID = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from llvm::ErrorInfo< StringError >
static const void * classID ()
 
- Static Public Member Functions inherited from llvm::ErrorInfoBase
static const void * classID ()
 

Detailed Description

This class wraps a string in an Error.

StringError is useful in cases where the client is not expected to be able to consume the specific error message programmatically (for example, if the error message is to be presented to the user).

StringError can also be used when additional information is to be printed along with a error_code message. Depending on the constructor called, this class can either display:

  1. the error_code message (ECError behavior)
  2. a string
  3. the error_code message and a string

These behaviors are useful when subtyping is required; for example, when a specific library needs an explicit error type. In the example below, PDBError is derived from StringError:

return llvm::make_error<PDBError>(pdb_error_code::dia_failed_loading,
"Additional information");
}
Tagged union holding either a T or a Error.
Definition: Error.h:481

Definition at line 1268 of file Error.h.

Constructor & Destructor Documentation

◆ StringError() [1/3]

llvm::StringError::StringError ( std::string &&  S,
std::error_code  EC,
bool  PrintMsgOnly 
)

Definition at line 146 of file Error.cpp.

◆ StringError() [2/3]

llvm::StringError::StringError ( std::error_code  EC,
const Twine S = Twine() 
)

Prints EC + S and converts to EC.

Definition at line 140 of file Error.cpp.

◆ StringError() [3/3]

llvm::StringError::StringError ( const Twine S,
std::error_code  EC 
)

Prints S and converts to EC.

Definition at line 143 of file Error.cpp.

Member Function Documentation

◆ convertToErrorCode()

std::error_code llvm::StringError::convertToErrorCode ( ) const
overridevirtual

Convert this error to a std::error_code.

This is a temporary crutch to enable interaction with code still using std::error_code. It will be removed in the future.

Implements llvm::ErrorInfoBase.

Definition at line 159 of file Error.cpp.

Referenced by llvm::msf::MSFError::isPageOverflow().

◆ getMessage()

const std::string & llvm::StringError::getMessage ( ) const
inline

Definition at line 1281 of file Error.h.

◆ log()

void llvm::StringError::log ( raw_ostream OS) const
overridevirtual

Print an error message to an output stream.

Implements llvm::ErrorInfoBase.

Definition at line 149 of file Error.cpp.

Member Data Documentation

◆ ID

char llvm::StringError::ID = 0
static

Definition at line 1270 of file Error.h.


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