Added throw specification.
[libsex.git] / include / libsex / Exception.hxx
blobfc9a7385191c90e21450ce097ed854eaaa3fe254
1 #ifndef EXCEPTION_HXX
2 #define EXCEPTION_HXX
4 #include <exception> // std::exception
5 #include <stdexcept> // std::bad_alloc
6 #include <ostream> // std::ostream
8 namespace libsex {
10 /**
11 * @brief Resembles a generic error, stores a
12 * message and optionally references one
13 * previous error (linked list).
15 * For OO error handling you should subclass this
16 * class for every type of error. Inheriting by
17 * hand is tedious, you usally don't want to do
18 * this. There are some efficient macros in @file
19 * create.hxx.
21 * @note The previous exceptions, if any, will
22 * be copied by calling clone() which may
23 * in turn throw bad_alloc. In that case, a
24 * notice is appended to this message (if
25 * enough chars left) and the exception is
26 * swallowed.
28 class Exception : public std::exception
30 public:
31 static const unsigned short LENGTH = 500;
33 Exception(const char* const message) throw();
34 Exception(
35 const char* const message,
36 const Exception& previous) throw();
37 virtual ~Exception() throw();
39 void write(std::ostream& out) const throw(std::ios_base::failure);
40 void backtrace(std::ostream& out) const throw(std::ios_base::failure);
42 virtual const Exception* clone() const
43 throw(std::bad_alloc) ;
45 virtual const char* what() const throw();
47 private:
48 /**
49 * @brief Copy of message passed to constructor.
51 * Length is Exception::LENGTH plus nullbyte.
53 char _message[LENGTH + 1];
54 const Exception* _previous;
56 void _initMessage(const char* const message);
59 }; // namespace
61 #endif