12 #include <boost/exception/diagnostic_information.hpp>
23 : stacktrace(NULL),n_stacktrace_frames(0)
31 : stacktrace(NULL), n_stacktrace_frames( other.n_stacktrace_frames)
36 char *ptr_dest = (
char *)(
stacktrace + n_stacktrace_frames);
40 while(*ptr_src!=0) *(ptr_dest++) = *(ptr_src++);
77 out <<
"** Stacktrace **" << endl;
82 if ( frame.find(
"boost") != string::npos
83 && frame.find(
"exception_detail") != string::npos
84 && frame.find(
"throw_exception") != string::npos
89 unsigned int out_i_frame=0;
92 unsigned int start_pos = frame.find(
"(")+1,
93 end_pos = frame.find(
"+");
94 string magled_fname = frame.substr( start_pos, end_pos-start_pos );
97 char *demagled_f_name = {0};
100 demagled_f_name = abi::__cxa_demangle(magled_fname.c_str(), 0, 0, &status);
103 out << setw(3) << out_i_frame <<
" " << demagled_f_name << endl;
104 free(demagled_f_name);
106 out << setw(3) << out_i_frame <<
" " << magled_fname << endl;
109 if (magled_fname ==
"main")
break;
119 static std::string message(1024,
' ');
123 std::ostringstream converter;
125 converter << std::endl << std::endl;
126 converter <<
"--------------------------------------------------------" << std::endl;
127 converter <<
"Program Error: ";
130 converter <<
"\n** Diagnosting info **\n" ;
131 converter << boost::diagnostic_information_what( *
this );
133 converter <<
"--------------------------------------------------------" << std::endl;
135 message = converter.str();
136 return message.c_str();
138 }
catch (std::exception &exc) {
139 std::cerr <<
"*** Exception encountered in exception handling routines ***" << std::endl <<
"*** Message is " << std::endl
140 << exc.what() << std::endl <<
"*** Aborting! ***" << std::endl;
144 std::cerr <<
"*** Exception encountered in exception handling routines ***" << std::endl <<
"*** Aborting! ***"
virtual const char * what() const
ExceptionBase()
Default constructor, just calls fill_stacktrace().
void fill_stacktrace()
Call GNU backtrace if available, save call stack information into stacktrace member.
virtual ~ExceptionBase()
Destructor, possibly free stacktrace.
Base of exceptions used in Flow123d.
char ** stacktrace
Array of backtrace frames returned by glibc backtrace_symbols.
void print_stacktrace(std::ostream &out) const
Prints formated stacktrace into given stream out.
int n_stacktrace_frames
Size of stacktrace table - number of frames.
virtual void print_info(std::ostringstream &out) const =0