Public Member Functions | List of all members
BPrivate::Network::BError Class Referenceabstract

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. More...
 
 BError (BString origin)
 Constructor that sets the origin. More...
 
 BError (const BError &error)
 Copy constructor. More...
 
 BError (const char *origin)
 Constructor that sets the origin. More...
 
virtual ~BError () noexcept
 Standard destructor. More...
 
virtual BString DebugMessage () const
 Retrieve a debug message that contains all info in this error. More...
 
virtual const char * Message () const noexcept=0
 Access the string representation of the message. More...
 
BErroroperator= (BError &&error) noexcept
 Move assignment operator. More...
 
BErroroperator= (const BError &error)
 Copy assignment operator. More...
 
virtual const char * Origin () const noexcept
 Access the string representation of the origin of the error. More...
 
size_t WriteToOutput (BDataIO *output) const
 Write the error description to an output. More...
 
void WriteToStream (std::ostream &stream) const
 Write the error description to an output stream. More...
 

Detailed Description

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.

Note
The advanced error objects are not used in the existing legacy Haiku Kits. They are being tested for use in the modern parts of the API and are therefore included in the network services kit.
Since
Haiku R1

Constructor & Destructor Documentation

◆ BError() [1/4]

BPrivate::Network::BError::BError ( const char *  error)

Constructor that sets the origin.

Since
Haiku R1

◆ BError() [2/4]

BPrivate::Network::BError::BError ( BString  origin)

Constructor that sets the origin.

Since
Haiku R1

◆ ~BError()

BPrivate::Network::BError::~BError ( )
virtualnoexcept

Standard destructor.

Since
Haiku R1

◆ BError() [3/4]

BPrivate::Network::BError::BError ( const BError other)

Copy constructor.

Since
Haiku R1

◆ BError() [4/4]

BPrivate::Network::BError::BError ( BError &&  other)
noexcept

Move constructor.

Since
Haiku R1

Member Function Documentation

◆ DebugMessage()

virtual BString BPrivate::Network::BError::DebugMessage ( ) const
virtual

Retrieve a debug message that contains all info in this error.

[Origin] Message of error
Exceptions
std::bad_allocIn the future this method may throw this exception when the memory for the debug message cannot be allocated.
Returns
A BString object that contains the debug message.
Since
Haiku R1

Reimplemented in BPrivate::Network::BSystemError, BPrivate::Network::BHttpFields::InvalidInput, BPrivate::Network::BHttpMethod::InvalidMethod, BPrivate::Network::BNetworkRequestError, and BPrivate::Network::BHttpTime::InvalidInput.

◆ Message()

const char * BPrivate::Network::BError::Message ( ) const
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.

Since
Haiku R1

Implemented in BPrivate::Network::BSystemError, BPrivate::Network::BHttpFields::InvalidInput, BPrivate::Network::BHttpMethod::InvalidMethod, BPrivate::Network::BNetworkRequestError, BPrivate::Network::BRuntimeError, BPrivate::Network::BHttpTime::InvalidInput, BPrivate::Network::BInvalidUrl, BPrivate::Network::BUnsupportedProtocol, and BPrivate::Network::BBorrowError.

◆ operator=() [1/2]

BError & BPrivate::Network::BError::operator= ( BError &&  other)
noexcept

Move assignment operator.

Since
Haiku R1

◆ operator=() [2/2]

BError & BPrivate::Network::BError::operator= ( const BError other)

Copy assignment operator.

Since
Haiku R1

◆ Origin()

const char * BPrivate::Network::BError::Origin ( ) const
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.

Since
Haiku R1

◆ WriteToOutput()

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.

Exceptions
BSystemErrorFor any error that occurs when calling BDataIO::Write()
Returns
The number of bytes that was written to output.
Since
Haiku R1

◆ WriteToStream()

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.

Exceptions
std::ios_base::failureAny error that is forwarded when writing to the stream.
Since
Haiku R1
BPrivate::Network::BError::Message
virtual const char * Message() const noexcept=0
Access the string representation of the message.
BPrivate::Network::BError::Origin
virtual const char * Origin() const noexcept
Access the string representation of the origin of the error.