--- /dev/null
+#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()