X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FException.hh;h=c6f32572797c72dfe7ee348a4b6cee148ff0a83a;hb=674621c6c6d1d8519b926f4bd830d9f84e9009c0;hp=7abf26cbbc5b0644fd25829c2f63c44d1cf9221f;hpb=be33ff96c5b89738694da272d8610564cce48bfb;p=senf.git diff --git a/Utils/Exception.hh b/Utils/Exception.hh index 7abf26c..c6f3257 100644 --- a/Utils/Exception.hh +++ b/Utils/Exception.hh @@ -23,8 +23,8 @@ /** \file \brief Exception public header */ -#ifndef HH_Exception_ -#define HH_Exception_ 1 +#ifndef HH_SENF_Utils_Exception_ +#define HH_SENF_Utils_Exception_ 1 // Custom includes #include @@ -96,9 +96,9 @@ SENF_WRAP_EXC(std::bad_cast) SENF_WRAP_EXC(somelib::FooException) } - \endcode The re-thrown exception can then be caught as std::bad_cast or as - senf::ExceptionMixin as needed. It is safe, to wrap an exception twice (the macro will detect - this case). + \endcode + The re-thrown exception can then be caught as std::bad_cast or as senf::ExceptionMixin + as needed. It is safe, to wrap an exception twice (the macro will detect this case). \code bar() { try { @@ -140,9 +140,10 @@ namespace senf { class ExceptionMixin { public: - std::string const & message() const; + std::string message() const; ///< get exception description + std::string backtrace() const; ///< Return backtrace (if available) - void append(std::string text); ///< Extend exception description + void append(std::string text); ///< Extend exception description /**< Adds \a text to the description text. */ protected: @@ -153,11 +154,12 @@ namespace senf { describing the exception for most derived exceptions. */ + std::string what_; private: #ifdef SENF_DEBUG void addBacktrace(); + std::string::size_type excLen_; #endif - std::string message_; }; /** \brief Extensible exception base-class @@ -177,6 +179,9 @@ namespace senf { virtual ~Exception() throw(); virtual char const * what() const throw(); + ///< get exception description and backtrace if available + /**< get description of the exception (message()) and backtrace + information if SENF is compiled with \c SENF_DEBUG */ protected: explicit Exception(std::string const & description = ""); @@ -261,7 +266,7 @@ namespace senf { the exception description: \code // Standard usage: Take \c errno from environment - SENF_THROW_SYSTEM_EXCEPTION() + SENF_THROW_SYSTEM_EXCEPTION("::open()") << " while opening configuration file: " << filename; // You may however explicitly specify the errno value @@ -299,7 +304,6 @@ namespace senf { void init(std::string const & descr, int code _SENF_EXC_DEBUG_ARGS_ND); int code_; - std::string what_; }; # ifdef SENF_DEBUG @@ -308,7 +312,7 @@ namespace senf { # define SENF_EXC_DEBUGINFO # endif -# define SENF_THROW_SYSTEM_EXCEPTION(desc) throw SystemException(desc SENF_EXC_DEBUGINFO) +# define SENF_THROW_SYSTEM_EXCEPTION(desc) throw senf::SystemException(desc SENF_EXC_DEBUGINFO) }