dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / scd_exception.cpp
diff --git a/dol/src/dol/visitor/hdsd/scd/scd_exception.cpp b/dol/src/dol/visitor/hdsd/scd/scd_exception.cpp
new file mode 100644 (file)
index 0000000..f5eb4f8
--- /dev/null
@@ -0,0 +1,35 @@
+#include "scd_exception.h"
+
+
+scd_exception::scd_exception(const std::string& msg): _msg(msg)
+{
+    _get_backtrace();
+}
+
+
+scd_exception::scd_exception(const std::string& msg, int errn)
+{
+    _msg = msg + ": " + std::string(strerror(errn));
+    _get_backtrace();
+}
+
+
+const char* scd_exception::what() throw() { return _msg.c_str(); }
+
+
+const char* scd_exception::stacktrace() { return _backtrace.c_str(); }
+
+
+void scd_exception::_get_backtrace()
+{
+    void* traces[SCD_EX_TRACES];
+    int num_traces = backtrace(traces, SCD_EX_TRACES);
+    char ** symbols = backtrace_symbols(traces, num_traces);
+    for (int i = 0; i < num_traces; i++)
+    {
+        _backtrace += std::string(symbols[i]);
+        _backtrace += "\r\n";
+    }
+
+    free(symbols);
+} // _obtain_backtrace()