Abstract base class for advanced error objects. More...
Inherited by BPrivate::Network::BBorrowError, BPrivate::Network::BHttpFields::InvalidInput, BPrivate::Network::BHttpMethod::InvalidMethod, BPrivate::Network::BHttpTime::InvalidInput, BPrivate::Network::BInvalidUrl, BPrivate::Network::BNetworkRequestError, BPrivate::Network::BRuntimeError, BPrivate::Network::BSystemError, and BPrivate::Network::BUnsupportedProtocol.
Public Member Functions | |
BError (BError &&error) noexcept | |
Move constructor. | |
BError (BString origin) | |
Constructor that sets the origin. | |
BError (const BError &error) | |
Copy constructor. | |
BError (const char *origin) | |
Constructor that sets the origin. | |
virtual | ~BError () noexcept |
Standard destructor. | |
virtual BString | DebugMessage () const |
Retrieve a debug message that contains all info in this error. | |
virtual const char * | Message () const noexcept=0 |
Access the string representation of the message. | |
BError & | operator= (BError &&error) noexcept |
Move assignment operator. | |
BError & | operator= (const BError &error) |
Copy assignment operator. | |
virtual const char * | Origin () const noexcept |
Access the string representation of the origin of the error. | |
size_t | WriteToOutput (BDataIO *output) const |
Write the error description to an output. | |
void | WriteToStream (std::ostream &stream) const |
Write the error description to an output stream. | |
Abstract base class for advanced error objects.
This class defines the minimum interface for advanced error objects in modern parts of the Haiku API.
The minimum definition of an error is that it contains an origin and a message. The origin should contain a string that helps a developer identify the origin of the error. Common practise is to pass the __PRETTY_FUNCTION__
from the place where the error is constructed, but subclasses can have their own definitions for the origin.
The message is a freeform message that describes the exact error condition. While it is not meant as a user-facing message, when creating custom error objects, take into account that a user may be confronted with a message in situations where an application presents it to a user as a final resort.
BPrivate::Network::BError::BError | ( | const char * | error | ) |
Constructor that sets the origin.
BPrivate::Network::BError::BError | ( | BString | origin | ) |
Constructor that sets the origin.
|
virtualnoexcept |
Standard destructor.
BPrivate::Network::BError::BError | ( | const BError & | other | ) |
Copy constructor.
|
noexcept |
Move constructor.
|
virtual |
Retrieve a debug message that contains all info in this error.
std::bad_alloc | In the future this method may throw this exception when the memory for the debug message cannot be allocated. |
Reimplemented in BPrivate::Network::BSystemError, BPrivate::Network::BHttpFields::InvalidInput, BPrivate::Network::BHttpMethod::InvalidMethod, BPrivate::Network::BHttpTime::InvalidInput, and BPrivate::Network::BNetworkRequestError.
|
pure virtualnoexcept |
Access the string representation of the message.
Implementations should return a meaningful description of the error that occured. The primary target audience of these messages are developers, who (hopefully) see them during development, testing or in bug reports. However, if it makes sense to have the error messages be instructive to users too, then do not hesitate to do so.
Implementations of this function should never return NULL
.
Implemented in BPrivate::Network::BRuntimeError, BPrivate::Network::BSystemError, BPrivate::Network::BBorrowError, BPrivate::Network::BHttpFields::InvalidInput, BPrivate::Network::BHttpMethod::InvalidMethod, BPrivate::Network::BHttpTime::InvalidInput, BPrivate::Network::BUnsupportedProtocol, BPrivate::Network::BInvalidUrl, and BPrivate::Network::BNetworkRequestError.
Move assignment operator.
Copy assignment operator.
|
virtualnoexcept |
Access the string representation of the origin of the error.
The default implementation returns a pointer to the string that was set as the origin when this object was constructed.
Implementations of this function should never return NULL
.
size_t BPrivate::Network::BError::WriteToOutput | ( | BDataIO * | output | ) | const |
Write the error description to an output.
The default implementation will use the output from DebugMessage() and write it to the output, including a newline and the NUL that terminates the string.
BSystemError | For any error that occurs when calling BDataIO::Write() |
void BPrivate::Network::BError::WriteToStream | ( | std::ostream & | stream | ) | const |
Write the error description to an output stream.
The default implementation will write the output of the DebugMessage() method, and append a newline.
std::ios_base::failure | Any error that is forwarded when writing to the stream. |