16 #include <deal.II/base/exceptions.h> 17 #include <deal.II/base/logstream.h> 23 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 24 # include <execinfo.h> 27 #ifdef DEAL_II_HAVE_LIBSTDCXX_DEMANGLER 31 DEAL_II_NAMESPACE_OPEN
37 std::string additional_assert_output;
41 additional_assert_output = p;
44 bool show_stacktrace =
true;
48 show_stacktrace =
false;
51 bool abort_on_exception =
true;
55 abort_on_exception =
false;
70 n_stacktrace_frames (0),
115 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 125 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 151 out <<
"An error occurred in line <" <<
line 152 <<
"> of file <" <<
file 153 <<
"> in function" << std::endl
154 <<
" " <<
function << std::endl
155 <<
"The violated condition was: "<< std::endl
156 <<
" " <<
cond << std::endl
157 <<
"The name and call sequence of the exception was:" << std::endl
158 <<
" " <<
exc << std::endl
159 <<
"Additional Information: " << std::endl;
166 out <<
"(none)" << std::endl;
176 if (deal_II_exceptions::show_stacktrace ==
false)
181 out <<
"Stacktrace:" << std::endl
182 <<
"-----------" << std::endl;
191 ((std::string(
stacktrace[frame]).find (
"ExceptionBase") != std::string::npos)
193 (std::string(
stacktrace[frame]).find (
"deal_II_exceptions") != std::string::npos)))
197 const unsigned int first_significant_frame = frame;
200 out <<
'#' << frame - first_significant_frame
206 std::string stacktrace_entry (
stacktrace[frame]);
207 const unsigned int pos_start = stacktrace_entry.find(
'('),
208 pos_end = stacktrace_entry.find(
'+');
209 std::string functionname = stacktrace_entry.substr (pos_start+1,
210 pos_end-pos_start-1);
216 #ifdef DEAL_II_HAVE_LIBSTDCXX_DEMANGLER 218 char *p = abi::__cxa_demangle(functionname.c_str(), 0, 0, &status);
220 if ((status == 0) && (functionname !=
"main"))
222 std::string realname(p);
229 while (realname.find (
", boost::tuples::null_type>")
230 != std::string::npos)
231 realname.erase (realname.find (
", boost::tuples::null_type>"),
232 std::string (
", boost::tuples::null_type").size());
234 stacktrace_entry = stacktrace_entry.substr(0, pos_start)
241 stacktrace_entry = stacktrace_entry.substr(0, pos_start)
251 stacktrace_entry = stacktrace_entry.substr(0, pos_start)
259 out << stacktrace_entry
263 if (functionname ==
"main")
277 std::ostringstream converter;
279 converter << std::endl
280 <<
"--------------------------------------------------------" 289 if (!deal_II_exceptions::additional_assert_output.empty())
291 converter <<
"--------------------------------------------------------" 293 << deal_II_exceptions::additional_assert_output
297 converter <<
"--------------------------------------------------------" 305 what_str =
"ExceptionBase::generate_message () failed";
318 if (::deal_II_exceptions::abort_on_exception)
321 std::cerr << exc.
what() << std::endl;
329 deallog <<
"Exception: " << exc.
get_exc_name() << std::endl;
345 DEAL_II_NAMESPACE_CLOSE
357 #ifdef DEAL_II_HAVE_VERBOSE_TERMINATE 360 extern void __verbose_terminate_handler ();
365 struct preload_terminate_dummy
367 preload_terminate_dummy()
369 std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
373 static preload_terminate_dummy dummy;
void suppress_stacktrace_in_exceptions()
void set_additional_assert_output(const char *const p)
virtual void print_info(std::ostream &out) const
void abort(const ExceptionBase &exc, bool nothrow=false)
void set_fields(const char *file, const int line, const char *function, const char *cond, const char *exc_name)
virtual const char * what() const
void print_stack_trace(std::ostream &out) const
void print_exc_data(std::ostream &out) const
void generate_message() const
void disable_abort_on_exception()
const char * get_exc_name() const