]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[support8785] Verbose Exception::what() has been implemented.
authorTomek Mrugalski <tomasz@isc.org>
Mon, 17 Aug 2015 19:33:53 +0000 (21:33 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Thu, 20 Aug 2015 12:57:05 +0000 (14:57 +0200)
  This change by itself does nothing, but it allows changing
  e.what() to e.what(true) to get more details about an exception.
  This can be useful for exception debugging.

src/lib/exceptions/exceptions.cc
src/lib/exceptions/exceptions.h

index 2a374da41859472de187ef8d2cd1c528a85905f7..d1ed651010dd38fa29ad61b3e1d308df053e1345 100644 (file)
@@ -22,18 +22,30 @@ namespace isc {
 
 const char*
 Exception::what() const throw() {
+    return (what(false));
+}
+
+const char*
+Exception::what(bool verbose) const throw() {
+
     const char* whatstr = "isc::Exception";
 
-    // XXX: even though it's very unlikely that c_str() throws an exception,
+    // XXX: Even though it's very unlikely that c_str() throws an exception,
     // it's still not 100% guaranteed.  To meet the exception specification
     // of this function, we catch any unexpected exception and fall back to
     // the pre-defined constant.
     try {
-        whatstr = what_.c_str();
+        if (verbose) {
+            static std::stringstream location;
+            location.str("");
+            location << what_ << "[" << file_ << ":" << line_ << "]";
+            whatstr = location.str().c_str();
+        } else {
+            whatstr = what_.c_str();
+        }
     } catch (...) {
         // no exception handling is necessary.  just have to catch exceptions.
     }
-
     return (whatstr);
 }
 
index d7e270dbabae9c57436c31f7c32ffbb3011b311d..e9dc3d6d1deaac23fcb7e8a4a0d960d55cfc4437 100644 (file)
@@ -73,6 +73,16 @@ public:
     ///
     /// @return A C-style character string of the exception cause.
     virtual const char* what() const throw();
+
+    /// \brief Returns a C-style charater string of the cause of exception.
+    ///
+    /// With verbose set to true, also returns file name and line numbers.
+    /// Note that we can't simply define a single what() method with parameters,
+    /// as the compiler would complain that it shadows the base class method.
+    ///
+    /// \param verbose if set to true, filename and line number will be added.
+    /// \return A C-style character string of the exception cause.
+    virtual const char* what(bool verbose) const throw();
     //@}
 
     ///