26#ifdef DEAL_II_WITH_MPI
32#ifdef DEAL_II_TRILINOS_WITH_SEACAS
36#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
40#ifdef DEAL_II_HAVE_LIBSTDCXX_DEMANGLER
54 static std::string additional_assert_output;
55 return additional_assert_output;
104 , n_stacktrace_frames(0)
107#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
117 , function(exc.function)
120 , n_stacktrace_frames(exc.n_stacktrace_frames)
124#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
128 std::copy(std::begin(
exc.raw_stacktrace),
129 std::end(
exc.raw_stacktrace),
154#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
185 out <<
"An error occurred in line <" <<
line <<
"> of file <" <<
file
186 <<
"> in function" << std::endl
199 if ((
cond !=
nullptr) && (std::strcmp(
cond,
"false") != 0))
200 out <<
"The violated condition was: " << std::endl
201 <<
" " <<
cond << std::endl;
221 if ((
exc !=
nullptr) &&
222 ((
cond ==
nullptr) ||
223 (std::strstr(
cond,
"::ExcMessage") !=
nullptr)))
224 out <<
"The name and call sequence of the exception was:" << std::endl
225 <<
" " <<
exc << std::endl;
228 out <<
"Additional information: " << std::endl;
236 out <<
" (none)" << std::endl;
250 char **stacktrace =
nullptr;
251#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
261 out <<
"Stacktrace:" << std::endl <<
"-----------" << std::endl;
269 ((std::string(stacktrace[frame]).find(
"ExceptionBase") !=
270 std::string::npos) ||
271 (std::string(stacktrace[frame]).find(
"deal_II_exceptions") !=
276 const unsigned int first_significant_frame = frame;
279 out <<
'#' << frame - first_significant_frame <<
" ";
284 std::string stacktrace_entry(stacktrace[frame]);
285 const unsigned int pos_start = stacktrace_entry.find(
'('),
286 pos_end = stacktrace_entry.find(
'+');
287 std::string functionname =
288 stacktrace_entry.substr(pos_start + 1, pos_end - pos_start - 1);
290 std::string demangled_stacktrace_entry =
291 stacktrace_entry.substr(0, pos_start);
292 demangled_stacktrace_entry +=
": ";
298#ifdef DEAL_II_HAVE_LIBSTDCXX_DEMANGLER
301 abi::__cxa_demangle(functionname.c_str(),
nullptr,
nullptr, &status);
303 if ((status == 0) && (functionname !=
"main"))
305 std::string realname(p);
312 while (realname.find(
", boost::tuples::null_type>") !=
314 realname.erase(realname.find(
", boost::tuples::null_type>"),
315 std::string(
", boost::tuples::null_type").size());
317 demangled_stacktrace_entry += realname;
320 demangled_stacktrace_entry += functionname;
326 demangled_stacktrace_entry += functionname;
330 out << demangled_stacktrace_entry << std::endl;
333 if (functionname ==
"main")
337 std::free(stacktrace);
338 stacktrace =
nullptr;
351 std::ostringstream converter;
353 converter << std::endl
354 <<
"--------------------------------------------------------"
364 std::ostringstream message;
367 const auto message_in_lines =
371 for (
const auto &
line : message_in_lines)
372 converter <<
" " <<
line <<
'\n';
382 <<
"--------------------------------------------------------"
388 converter <<
"--------------------------------------------------------"
396 what_str =
"ExceptionBase::generate_message () failed";
404#ifdef DEAL_II_WITH_MPI
406 : error_code(error_code)
412 char error_name[MPI_MAX_ERROR_STRING];
413 error_name[0] =
'\0';
414 int resulting_length = MPI_MAX_ERROR_STRING;
416 bool error_name_known =
false;
424 int ierr = MPI_Error_class(
error_code, &error_class);
425 error_name_known = (ierr == MPI_SUCCESS);
429 if (error_name_known)
431 ierr = MPI_Error_string(error_class, error_name, &resulting_length);
432 error_name_known = error_name_known && (ierr == MPI_SUCCESS);
436 out <<
"deal.II encountered an error while calling an MPI function."
438 if (error_name_known)
440 out <<
"The description of the error provided by MPI is \""
441 << error_name <<
"\"." << std::endl;
446 <<
"This error code is not equal to any of the standard MPI error codes."
449 out <<
"The numerical value of the original error code is " <<
error_code
456#ifdef DEAL_II_TRILINOS_WITH_SEACAS
458 : error_code(error_code)
462 static_assert(EX_NOERR == 0,
463 "EX_NOERR is assumed to be zero in all versions of ExodusII");
471 out <<
"Error code is " <<
error_code <<
'\n';
472 out <<
"String description: " << ex_strerror(
error_code) <<
'\n';
485 std::cerr << exc.what() << std::endl;
499#ifdef DEAL_II_WITH_MPI
501 MPI_Initialized(&is_initialized);
502 if (is_initialized != 0)
510 <<
"Calling MPI_Abort now.\n"
511 <<
"To break execution in a GDB session, execute 'break MPI_Abort' before "
512 <<
"running. You can also put the following into your ~/.gdbinit:\n"
513 <<
" set breakpoint pending on\n"
514 <<
" break MPI_Abort\n"
515 <<
" set breakpoint pending auto" << std::endl;
517 MPI_Abort(MPI_COMM_WORLD,
527#if KOKKOS_VERSION < 30200
528 if constexpr (std::is_same_v<Kokkos::DefaultExecutionSpace,
529 Kokkos::DefaultHostExecutionSpace>)
540 "Abort() was called during dealing with an assertion or exception.");
555 deallog <<
"Exception: " << exc.get_exc_name() << std::endl;
556 deallog << exc.what() << std::endl;
void generate_message() const
void print_stack_trace(std::ostream &out) const
const char * get_exc_name() const
void set_fields(const char *file, const int line, const char *function, const char *cond, const char *exc_name)
virtual void print_info(std::ostream &out) const
virtual const char * what() const noexcept override
void print_exc_data(std::ostream &out) const
void * raw_stacktrace[25]
ExcExodusII(const int error_code)
virtual void print_info(std::ostream &out) const override
virtual void print_info(std::ostream &out) const override
ExcMPI(const int error_code)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
std::vector< std::string > break_text_into_lines(const std::string &original_text, const unsigned int width, const char delimiter=' ')
void abort(const ExceptionBase &exc) noexcept
std::string & get_additional_assert_output()
void do_issue_error_nothrow(const ExceptionBase &e) noexcept
bool allow_abort_on_exception
void enable_abort_on_exception()
void disable_abort_on_exception()
void set_additional_assert_output(const char *const p)
void suppress_stacktrace_in_exceptions()