dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / scd_exception.h
1 #ifndef SCD_EXCEPTION_H
2 #define SCD_EXCEPTION_H
3
4 #include <string>
5 #include <exception>
6 #include <execinfo.h>
7
8
9 /**
10  * Maximum level of stacktrace.
11  */
12 const int SCD_EX_TRACES = 15;
13
14
15 /**
16  * General exeption. Can give a stack trace and generates error messages
17  * from error numbers.
18  */
19 class scd_exception : public std::exception
20 {
21 public:
22     /**
23      * Constructor to create an exception with a string as cause.
24      * \param the cause
25      */
26     scd_exception(const std::string& msg);
27
28     /**
29      * Constroctor to create an exception with a string and an error
30      * message generated from an error number (errno) as cause.
31      * \param the cause prefix
32      * \param the error number to generate the error message for
33      */
34     scd_exception(const std::string& msg, int errn);
35
36     virtual ~scd_exception() throw() {}
37
38     /**
39      * Returns a C-String showing the cause of the exception.
40      */
41     virtual const char* what() throw();
42
43     /**
44      * Returns a C-String showing the stack trace. For name resolution
45      * -rdynamic has to be used while compiling.
46      */
47     const char* stacktrace();
48
49 private:
50     std::string _msg;
51     std::string _backtrace;
52
53     void _get_backtrace();
54
55 };
56
57 #endif