libsex  3.1.0
simple exception library (C++)
Public Member Functions | Static Public Attributes
libsex::Exception Class Reference

Generic error made up of a message and (optional) references to previous one. More...

#include <Exception.hxx>

List of all members.

Public Member Functions

 Exception (const char *const message) throw ()
 Creates an exception.
 Exception (const char *const message, const Exception &previous) throw ()
 Creates a chained exception.
virtual ~Exception () throw ()
 No-op.
void write (std::ostream &out) const throw (std::ios_base::failure)
 Writes our message to passed stream.
void backtrace (std::ostream &out) const throw (std::ios_base::failure)
 Writes a backtrace to passed stream.
virtual const Exceptionclone () const throw (std::bad_alloc)
 Creates a shallow copy of this exception.
virtual const char * what () const throw ()
 Returns a pointer to the internal character string.

Static Public Attributes

static const unsigned short LENGTH = 500
 Max payload of the internal character string.

Detailed Description

Generic error made up of a message and (optional) references to previous one.

Double-fault save (not throwing std::bad_alloc or other exceptions in critical situations) and allows exception chaining.

For object-oriented error handling you should subclass this class for every type of error. There are elegant macros in


Constructor & Destructor Documentation

libsex::Exception::Exception ( const char *const  message) throw ()

Creates an exception.

Supplied character array should be null- terminated and should not exceed LENGTH characters (excl. null byte). Its contents will be copied into an internal buffer and can be overwritten/freed afterwards.

The constructors do not accept std::string since that class uses the heap and may throw std::bad_alloc -- which might obviously happen even before this constructor is entered and thus might result in loss of the actual (chain of) exception(s) describing the error.

Definition at line 10 of file Exception.cxx.

libsex::Exception::Exception ( const char *const  message,
const Exception previous 
) throw ()

Creates a chained exception.

Both the error message and the previous exception are cloned.

Since exceptions should be created on the stack (see std::bad_alloc), the previous one will be internally copied to the heap by calling clone().

If clone() throws std::bad_alloc, a notice is appended to the internal message buffer of this exception (as long as space left) and std::bad_alloc is swallowed.

See also:
Exception(message)

Definition at line 17 of file Exception.cxx.


Member Function Documentation

void libsex::Exception::backtrace ( std::ostream &  out) const throw (std::ios_base::failure)

Writes a backtrace to passed stream.

Messages are delimited by one newline and are printed in reverse chronological order.

Exceptions:
std::ios_base::failuremay be thrown by stream, if it is configured to do so.

Definition at line 57 of file Exception.cxx.

const libsex::Exception * libsex::Exception::clone ( ) const throw (std::bad_alloc) [virtual]

Creates a shallow copy of this exception.

Copy is allocated on the heap.

Exceptions:
std::bad_allocon memory shortage.

Definition at line 67 of file Exception.cxx.

void libsex::Exception::write ( std::ostream &  out) const throw (std::ios_base::failure)

Writes our message to passed stream.

Exceptions:
std::ios_base::failuremay be thrown by stream, if it is configured to do so.

Definition at line 51 of file Exception.cxx.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Defines