summaryrefslogtreecommitdiff
path: root/klm/util/exception.cc
diff options
context:
space:
mode:
authorKenneth Heafield <kenlm@kheafield.com>2011-07-07 21:01:38 -0400
committerKenneth Heafield <kenlm@kheafield.com>2011-07-07 21:01:38 -0400
commitf68aaa588a2e1eb7cef5a57d57dd7e86fd4b0c9a (patch)
treee2b6bc873303f5aac6e05961d30b316a6b3dcce3 /klm/util/exception.cc
parent71daf4bf0b91a247d0d1663ae7850a3db85a378d (diff)
Exception update
Diffstat (limited to 'klm/util/exception.cc')
-rw-r--r--klm/util/exception.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/klm/util/exception.cc b/klm/util/exception.cc
index 84f9fe7c..62280970 100644
--- a/klm/util/exception.cc
+++ b/klm/util/exception.cc
@@ -1,5 +1,9 @@
#include "util/exception.hh"
+#ifdef __GXX_RTTI
+#include <typeinfo>
+#endif
+
#include <errno.h>
#include <string.h>
@@ -22,6 +26,30 @@ const char *Exception::what() const throw() {
return text_.c_str();
}
+void Exception::SetLocation(const char *file, unsigned int line, const char *func, const char *child_name, const char *condition) {
+ /* The child class might have set some text, but we want this to come first.
+ * Another option would be passing this information to the constructor, but
+ * then child classes would have to accept constructor arguments and pass
+ * them down.
+ */
+ text_ = stream_.str();
+ stream_.str("");
+ stream_ << file << ':' << line;
+ if (func) stream_ << " in " << func << " threw ";
+ if (child_name) {
+ stream_ << child_name;
+ } else {
+#ifdef __GXX_RTTI
+ stream_ << typeid(this).name();
+#else
+ stream_ << "an exception";
+#endif
+ }
+ if (condition) stream_ << " because `" << condition;
+ stream_ << "'.\n";
+ stream_ << text_;
+}
+
namespace {
// The XOPEN version.
const char *HandleStrerror(int ret, const char *buf) {