aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/exceptionbase.cpp68
-rw-r--r--src/exceptionbase.h7
2 files changed, 0 insertions, 75 deletions
diff --git a/src/exceptionbase.cpp b/src/exceptionbase.cpp
index 6e5ae10..6d019af 100644
--- a/src/exceptionbase.cpp
+++ b/src/exceptionbase.cpp
@@ -11,70 +11,42 @@
11Bu::ExceptionBase::ExceptionBase( const char *lpFormat, ... ) throw() : 11Bu::ExceptionBase::ExceptionBase( const char *lpFormat, ... ) throw() :
12 nErrorCode( 0 ), 12 nErrorCode( 0 ),
13 sWhat( NULL ) 13 sWhat( NULL )
14#ifdef LIBBU_EXCEPTION_BACKTRACE
15 , sBT( NULL )
16#endif
17{ 14{
18 va_list ap; 15 va_list ap;
19 16
20 va_start(ap, lpFormat); 17 va_start(ap, lpFormat);
21 setWhat( lpFormat, ap ); 18 setWhat( lpFormat, ap );
22 va_end(ap); 19 va_end(ap);
23#ifdef LIBBU_EXCEPTION_BACKTRACE
24 createBacktrace();
25#endif
26} 20}
27 21
28Bu::ExceptionBase::ExceptionBase( int nCode, const char *lpFormat, ... ) throw() : 22Bu::ExceptionBase::ExceptionBase( int nCode, const char *lpFormat, ... ) throw() :
29 nErrorCode( nCode ), 23 nErrorCode( nCode ),
30 sWhat( NULL ) 24 sWhat( NULL )
31#ifdef LIBBU_EXCEPTION_BACKTRACE
32 , sBT( NULL )
33#endif
34{ 25{
35 va_list ap; 26 va_list ap;
36 27
37 va_start(ap, lpFormat); 28 va_start(ap, lpFormat);
38 setWhat( lpFormat, ap ); 29 setWhat( lpFormat, ap );
39 va_end(ap); 30 va_end(ap);
40#ifdef LIBBU_EXCEPTION_BACKTRACE
41 createBacktrace();
42#endif
43} 31}
44 32
45Bu::ExceptionBase::ExceptionBase( int nCode ) throw() : 33Bu::ExceptionBase::ExceptionBase( int nCode ) throw() :
46 nErrorCode( nCode ), 34 nErrorCode( nCode ),
47 sWhat( NULL ) 35 sWhat( NULL )
48#ifdef LIBBU_EXCEPTION_BACKTRACE
49 , sBT( NULL )
50#endif
51{ 36{
52#ifdef LIBBU_EXCEPTION_BACKTRACE
53 createBacktrace();
54#endif
55} 37}
56 38
57Bu::ExceptionBase::ExceptionBase( const ExceptionBase &e ) throw () : 39Bu::ExceptionBase::ExceptionBase( const ExceptionBase &e ) throw () :
58 nErrorCode( e.nErrorCode ), 40 nErrorCode( e.nErrorCode ),
59 sWhat( NULL ) 41 sWhat( NULL )
60#ifdef LIBBU_EXCEPTION_BACKTRACE
61 , sBT( NULL )
62#endif
63{ 42{
64 setWhat( e.sWhat ); 43 setWhat( e.sWhat );
65#ifdef LIBBU_EXCEPTION_BACKTRACE
66 createBacktrace();
67#endif
68} 44}
69 45
70Bu::ExceptionBase::~ExceptionBase() throw() 46Bu::ExceptionBase::~ExceptionBase() throw()
71{ 47{
72 delete[] sWhat; 48 delete[] sWhat;
73 sWhat = NULL; 49 sWhat = NULL;
74#ifdef LIBBU_EXCEPTION_BACKTRACE
75 delete[] sBT;
76 sBT = NULL;
77#endif
78} 50}
79 51
80void Bu::ExceptionBase::setWhat( const char *lpFormat, va_list &vargs ) 52void Bu::ExceptionBase::setWhat( const char *lpFormat, va_list &vargs )
@@ -107,43 +79,3 @@ int Bu::ExceptionBase::getErrorCode()
107 return nErrorCode; 79 return nErrorCode;
108} 80}
109 81
110#ifdef LIBBU_EXCEPTION_BACKTRACE
111const char *Bu::ExceptionBase::getBacktrace() const throw()
112{
113 return sBT;
114}
115
116#include "bu/fstring.h"
117#include <execinfo.h>
118
119void Bu::ExceptionBase::createBacktrace()
120{
121 void *array[1000];
122 size_t size;
123 char **strings;
124 size_t i;
125
126 size = backtrace (array, 1000);
127 strings = backtrace_symbols (array, size);
128
129 Bu::FString s;
130 s.format("Obtained %zd stack frames.\n", size );
131
132 for (i = 0; i < size; i++)
133 {
134 s += strings[i];
135 s += "\n";
136 }
137
138 free (strings);
139
140 sBT = new char[s.getSize()+1];
141 strcpy( sBT, s.getStr() );
142}
143
144#else
145const char *Bu::ExceptionBase::getBacktrace() const throw()
146{
147 return "Backtrace support is not compiled in.\n";
148}
149#endif
diff --git a/src/exceptionbase.h b/src/exceptionbase.h
index 4d1d2ff..37f4418 100644
--- a/src/exceptionbase.h
+++ b/src/exceptionbase.h
@@ -16,7 +16,6 @@
16// and it also changes the class interface, we should find out how much of 16// and it also changes the class interface, we should find out how much of
17// an issue that is, we could just put in an empty getBacktrace() function for 17// an issue that is, we could just put in an empty getBacktrace() function for
18// when you don't have support for it... 18// when you don't have support for it...
19#define LIBBU_EXCEPTION_BACKTRACE
20 19
21namespace Bu 20namespace Bu
22{ 21{
@@ -89,15 +88,9 @@ namespace Bu
89 */ 88 */
90 void setWhat( const char *lpText ); 89 void setWhat( const char *lpText );
91 90
92 const char *getBacktrace() const throw();
93
94 private: 91 private:
95 int nErrorCode; /**< The code for the error that occured. */ 92 int nErrorCode; /**< The code for the error that occured. */
96 char *sWhat; /**< The text string telling people what went wrong. */ 93 char *sWhat; /**< The text string telling people what went wrong. */
97#ifdef LIBBU_EXCEPTION_BACKTRACE
98 char *sBT; /**< The backtrace text. */
99 void createBacktrace();
100#endif
101 }; 94 };
102} 95}
103 96