16 #include <deal.II/base/exceptions.h> 17 #include <deal.II/base/logstream.h> 18 #include <deal.II/base/utilities.h> 19 #include <deal.II/base/mpi.h> 27 #ifdef DEAL_II_WITH_MPI 31 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 32 # include <execinfo.h> 35 #ifdef DEAL_II_HAVE_LIBSTDCXX_DEMANGLER 39 DEAL_II_NAMESPACE_OPEN
45 std::string additional_assert_output;
49 additional_assert_output = p;
52 bool show_stacktrace =
true;
56 show_stacktrace =
false;
59 bool abort_on_exception =
true;
63 abort_on_exception =
false;
78 n_stacktrace_frames (0),
81 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 93 function(exc.function),
97 n_stacktrace_frames (0),
100 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 133 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 143 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE 170 out <<
"An error occurred in line <" <<
line 171 <<
"> of file <" <<
file 172 <<
"> in function" << std::endl
173 <<
" " <<
function << std::endl
174 <<
"The violated condition was: "<< std::endl
175 <<
" " <<
cond << std::endl;
189 if (std::strstr(
cond,
"::ExcMessage") != NULL)
190 out <<
"The name and call sequence of the exception was:" << std::endl
191 <<
" " <<
exc << std::endl;
194 out <<
"Additional information: " << std::endl;
201 out <<
" (none)" << std::endl;
211 if (deal_II_exceptions::show_stacktrace ==
false)
216 out <<
"Stacktrace:" << std::endl
217 <<
"-----------" << std::endl;
226 ((std::string(
stacktrace[frame]).find (
"ExceptionBase") != std::string::npos)
228 (std::string(
stacktrace[frame]).find (
"deal_II_exceptions") != std::string::npos)))
232 const unsigned int first_significant_frame = frame;
235 out <<
'#' << frame - first_significant_frame
241 std::string stacktrace_entry (
stacktrace[frame]);
242 const unsigned int pos_start = stacktrace_entry.find(
'('),
243 pos_end = stacktrace_entry.find(
'+');
244 std::string functionname = stacktrace_entry.substr (pos_start+1,
245 pos_end-pos_start-1);
251 #ifdef DEAL_II_HAVE_LIBSTDCXX_DEMANGLER 253 char *p = abi::__cxa_demangle(functionname.c_str(), 0, 0, &status);
255 if ((status == 0) && (functionname !=
"main"))
257 std::string realname(p);
264 while (realname.find (
", boost::tuples::null_type>")
265 != std::string::npos)
266 realname.erase (realname.find (
", boost::tuples::null_type>"),
267 std::string (
", boost::tuples::null_type").size());
269 stacktrace_entry = stacktrace_entry.substr(0, pos_start)
276 stacktrace_entry = stacktrace_entry.substr(0, pos_start)
286 stacktrace_entry = stacktrace_entry.substr(0, pos_start)
294 out << stacktrace_entry
298 if (functionname ==
"main")
312 std::ostringstream converter;
314 converter << std::endl
315 <<
"--------------------------------------------------------" 324 if (!deal_II_exceptions::additional_assert_output.empty())
326 converter <<
"--------------------------------------------------------" 328 << deal_II_exceptions::additional_assert_output
332 converter <<
"--------------------------------------------------------" 340 what_str =
"ExceptionBase::generate_message () failed";
346 #ifdef DEAL_II_WITH_MPI 349 ExcMPI::ExcMPI (
const int error_code)
351 error_code (error_code)
354 void ExcMPI::print_info (std::ostream &out)
const 356 char error_name[MPI_MAX_ERROR_STRING];
357 error_name[0] =
'\0';
358 int resulting_length = MPI_MAX_ERROR_STRING;
360 bool error_name_known =
false;
363 if (error_code < MPI_ERR_LASTCODE)
368 int ierr = MPI_Error_class (error_code, &error_class);
369 error_name_known = (ierr == MPI_SUCCESS);
373 if (error_name_known)
375 ierr = MPI_Error_string (error_class, error_name, &resulting_length);
376 error_name_known = error_name_known && (ierr == MPI_SUCCESS);
380 out <<
"deal.II encountered an error while calling an MPI function." 382 if (error_name_known)
384 out <<
"The description of the error provided by MPI is \"" 391 out <<
"This error code is not equal to any of the standard MPI error codes." 394 out <<
"The numerical value of the original error code is " 400 #endif // DEAL_II_WITH_MPI 411 if (::deal_II_exceptions::abort_on_exception)
414 std::cerr << exc.
what() << std::endl;
422 deallog <<
"Exception: " << exc.
get_exc_name() << std::endl;
438 DEAL_II_NAMESPACE_CLOSE
450 #ifdef DEAL_II_HAVE_VERBOSE_TERMINATE 453 extern void __verbose_terminate_handler ();
458 struct preload_terminate_dummy
460 preload_terminate_dummy()
462 std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
466 static preload_terminate_dummy dummy;
void suppress_stacktrace_in_exceptions()
void set_additional_assert_output(const char *const p)
void * raw_stacktrace[25]
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 ~ExceptionBase() DEAL_II_NOEXCEPT
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
virtual const char * what() const DEAL_II_NOEXCEPT