dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / scd_exception.cpp
1 #include "scd_exception.h"
2
3
4 scd_exception::scd_exception(const std::string& msg): _msg(msg)
5 {
6     _get_backtrace();
7 }
8
9
10 scd_exception::scd_exception(const std::string& msg, int errn)
11 {
12     _msg = msg + ": " + std::string(strerror(errn));
13     _get_backtrace();
14 }
15
16
17 const char* scd_exception::what() throw() { return _msg.c_str(); }
18
19
20 const char* scd_exception::stacktrace() { return _backtrace.c_str(); }
21
22
23 void scd_exception::_get_backtrace()
24 {
25     void* traces[SCD_EX_TRACES];
26     int num_traces = backtrace(traces, SCD_EX_TRACES);
27     char ** symbols = backtrace_symbols(traces, num_traces);
28     for (int i = 0; i < num_traces; i++)
29     {
30         _backtrace += std::string(symbols[i]);
31         _backtrace += "\r\n";
32     }
33
34     free(symbols);
35 } // _obtain_backtrace()