PPI: Missing commit
[senf.git] / Utils / Exception.hh
index 840379e..a91b157 100644 (file)
@@ -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 <exception>
@@ -66,7 +66,7 @@
         // ...
     }
     catch (senf::ExceptionMixin & e) {
-        e << boost::format("\ncall id 0x%04x@%s") % id % address;
+        e << boost::format("\n" "call id 0x%04x@%s") % id % address;
     }
     \endcode
 
@@ -87,7 +87,7 @@
     the GNU-libc.
 
     To apply these features (extensibility, backtrace) to a non-senf exception, the non-senf
-    exception can be wrapped and rethrown.
+    exception can be wrapped and re-thrown.
     \code
     void foo() {
         try {
@@ -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 <tt>std::bad_cast</tt> 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 <tt>std::bad_cast</tt> or as senf::ExceptionMixin
+    as needed. It is safe, to wrap an exception twice (the macro will detect this case).
     \code
     bar() {
     try {
             foo();
         }
         catch (senf::ExceptionMixin & ex) {
-            ex << "\nadd this info";
+            ex << "\n" "add this info";
         }
     }
     catch (std::bad_cast const & ex) {
 
     \todo Link against libcwd to add file-name/line-number information to the backtrace and remove
         the dependency on -rdynamic
+    \todo Or better, use addr2line to obtain that information when showing the backtrace when
+        catched within Daemon (<tt>addr2line -fsiCe argv[0]</tt>)
+    \todo Add signal handlers for the bad signals which writes a backtrace to stderr and
+        terminates. This should probably write out a raw backtrace without de-mangling or
+        line-numbers since we don't want to mess with dynamic memory when the heap might be
+        corrupted ... Another handler for e.g. SIGUSR2 is nice to show a debug backtrace on demand
  */
 
 namespace senf {
@@ -134,9 +140,9 @@ namespace senf {
     class ExceptionMixin
     {
     public:
-        std::string const & message() const;
+        std::string const & message() const; ///< get exception description
 
-        void append(std::string text); ///< Extend exception description
+        void append(std::string text);  ///< Extend exception description
                                         /**< Adds \a text to the description text. */
 
     protected:
@@ -146,7 +152,7 @@ namespace senf {
                                              string. This should probably be a string constant
                                              describing the exception for most derived
                                              exceptions. */
-
+        std::string what_;
     private:
 #ifdef SENF_DEBUG
         void addBacktrace();
@@ -171,6 +177,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 = "");
@@ -255,7 +264,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
@@ -293,7 +302,6 @@ namespace senf {
         void init(std::string const & descr, int code _SENF_EXC_DEBUG_ARGS_ND);
         
         int code_;
-        std::string what_;
     };
 
 #   ifdef SENF_DEBUG
@@ -302,7 +310,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)
 
 }
 
@@ -322,3 +330,4 @@ namespace senf {
 // compile-command: "scons -u test"
 // comment-column: 40
 // End: