libfossil
fsl::Exception Class Reference

The base exception type used by the API. More...

#include "fossil.hpp"

Inheritance diagram for fsl::Exception:
fsl::OOMException

Public Member Functions

 Exception (Exception const &other) throw ()
 Copies the error message state from other. More...
 
 Exception (int code, std::string const &msg) throw ()
 Sets the error state from the given arguments. More...
 
 Exception (int code) throw ()
 Equivalent to Exception(code, fsl_rc_cstr(code)). More...
 
 Exception () throw ()
 A default-constructed exception with no message string and an error code of FSL_RC_ERROR. More...
 
 Exception (fsl_error &err) throw ()
 Moves err's contents into this object, effectively upgrading it to something we can throw. More...
 
 Exception (fsl_error const *err) throw ()
 Copies err's contents into this object, effectively upgrading it to something we can throw. More...
 
 Exception (int code, char const *fmt,...) throw ()
 Sets the error state from the given code (generally assumed to be a fsl_rc_t value!) and a formatted string, supporting the same formatting options as fsl_appendf() and friends. More...
 
 Exception (int code, char const *fmt, va_list) throw ()
 Equivalent to Exception(code,fmt,...) except that it takes a va_list. More...
 
virtual ~Exception () throw ()
 Cleans up any error string memory. More...
 
int code () const throw ()
 Returns the code passed to the constructor. More...
 
char const * codeString () const throw ()
 Equivalent to fsl_rc_cstr(this->code()). More...
 
char const * messsage () const throw ()
 Alias (for API consistency's sake) for what(). More...
 
 operator fsl_error * () throw ()
 Implicit conversion to simplify some integration with the C APIs. More...
 
 operator fsl_error const * () const throw ()
 Const-correct overload. More...
 
Exceptionoperator= (Exception const &other) throw ()
 Copies the error message state from other. More...
 
virtual char const * what () const throw ()
 Returns the message string provided to the ctor. More...
 

Detailed Description

The base exception type used by the API.

It follows the libfossil convention of returning errors as (if possible) an error code from the fsl_rc_t enum and a descriptive string (which generally defaults to the string-form of the FSL_RC_xxx constant value (see fsl_rc_cstr()).

Definition at line 54 of file fossil.hpp.

Constructor & Destructor Documentation

virtual fsl::Exception::~Exception ( )
throw (
)
virtual

Cleans up any error string memory.

fsl::Exception::Exception ( Exception const &  other)
throw (
)

Copies the error message state from other.

fsl::Exception::Exception ( int  code,
std::string const &  msg 
)
throw (
)

Sets the error state from the given arguments.

If msg.empty() then fsl_rc_cstr(code) is used as a message string.

fsl::Exception::Exception ( int  code)
throw (
)
explicit

Equivalent to Exception(code, fsl_rc_cstr(code)).

fsl::Exception::Exception ( )
throw (
)

A default-constructed exception with no message string and an error code of FSL_RC_ERROR.

Intended to be used in conjunction with the (fsl_error*) implicit conversion and C APIs taking a fsl_error pointer.

fsl::Exception::Exception ( fsl_error err)
throw (
)
explicit

Moves err's contents into this object, effectively upgrading it to something we can throw.

It is safe to pass a local stack-allocated fsl_error object provided it is properly initialized (via copy-construction from fsl_error_empty resp. fsl_error_empty_m) because this function takes its memory from it.

fsl::Exception::Exception ( fsl_error const *  err)
throw (
)
explicit

Copies err's contents into this object, effectively upgrading it to something we can throw.

Is generally intended to be passed the return value from, e.g. fsl_cx_err_get_e().

fsl::Exception::Exception ( int  code,
char const *  fmt,
  ... 
)
throw (
)

Sets the error state from the given code (generally assumed to be a fsl_rc_t value!) and a formatted string, supporting the same formatting options as fsl_appendf() and friends.

As a special case, if code==FSL_RC_OOM then the message string is ignored to avoid allocating memory for the error message.

When passing on strings from external sources, it is safest to pass "%s" as the format string and the foreign string as the first variadic argument. That ensures that percent signs in the foreign input do not get processed as format specifiers (which expect further arguments in the variadic list, which will likely lead to undefined behaviour).

fsl::Exception::Exception ( int  code,
char const *  fmt,
va_list   
)
throw (
)

Equivalent to Exception(code,fmt,...) except that it takes a va_list.

Member Function Documentation

int fsl::Exception::code ( ) const
throw (
)

Returns the code passed to the constructor.

char const* fsl::Exception::codeString ( ) const
throw (
)

Equivalent to fsl_rc_cstr(this->code()).

char const* fsl::Exception::messsage ( ) const
throw (
)

Alias (for API consistency's sake) for what().

fsl::Exception::operator fsl_error * ( )
throw (
)

Implicit conversion to simplify some integration with the C APIs.

fsl::Exception::operator fsl_error const * ( ) const
throw (
)

Const-correct overload.

Exception& fsl::Exception::operator= ( Exception const &  other)
throw (
)

Copies the error message state from other.

virtual char const* fsl::Exception::what ( ) const
throw (
)
virtual

Returns the message string provided to the ctor.

It's not called message() because this interface is inherited from std::exception.


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