Finished libSocket and libUtils documentation
[senf.git] / Utils / Exception.cc
index a534910..cc87f61 100644 (file)
 // Free Software Foundation, Inc.,
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
-// Definition of non-inline non-template functions
+/** \file
+    \brief Exception non-inline non-template implementation */
 
 #include "Exception.hh"
 //#include "Exception.ih"
 
 // Custom includes
 #include <cstring>
+#include <sstream>
 
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
 
-prefix_ char const * satcom::lib::SystemException::what()
+prefix_ void senf::SystemException::init()
+{
+    // We normallyl don't want to consume memory in an exception,
+    // however all other solutions to format the message are terribly
+    // ugly (since thay must use a static and shared buffer ...)
+    std::stringstream s;
+    if (where)
+        s << where << ": ";
+    s << "(" << err << ") " << std::strerror(err);
+    buffer_ = s.str();
+}
+
+prefix_ char const * senf::SystemException::what()
     const throw()
 {
-    return std::strerror(this->err);
+    return buffer_.c_str();
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////
@@ -43,5 +57,5 @@ prefix_ char const * satcom::lib::SystemException::what()
 \f
 // Local Variables:
 // mode: c++
-// c-file-style: "satcom"
+// c-file-style: "senf"
 // End: