26#ifdef DEAL_II_WITH_MPI
30#ifdef DEAL_II_TRILINOS_WITH_SEACAS
34#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
38#ifdef DEAL_II_HAVE_LIBSTDCXX_DEMANGLER
52 static std::string additional_assert_output;
53 return additional_assert_output;
102 , n_stacktrace_frames(0)
105#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
115 , function(exc.function)
118 , n_stacktrace_frames(exc.n_stacktrace_frames)
122#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
126 std::copy(std::begin(
exc.raw_stacktrace),
127 std::end(
exc.raw_stacktrace),
152#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
183 out <<
"An error occurred in line <" <<
line <<
"> of file <" <<
file
184 <<
"> in function" << std::endl
197 if ((
cond !=
nullptr) && (std::strcmp(
cond,
"false") != 0))
198 out <<
"The violated condition was: " << std::endl
199 <<
" " <<
cond << std::endl;
219 if ((
exc !=
nullptr) &&
220 ((
cond ==
nullptr) ||
221 (std::strstr(
cond,
"::ExcMessage") !=
nullptr)))
222 out <<
"The name and call sequence of the exception was:" << std::endl
223 <<
" " <<
exc << std::endl;
226 out <<
"Additional information: " << std::endl;
234 out <<
" (none)" << std::endl;
248 char **stacktrace =
nullptr;
249#ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
259 out <<
"Stacktrace:" << std::endl <<
"-----------" << std::endl;
267 ((std::string(stacktrace[frame]).find(
"ExceptionBase") !=
268 std::string::npos) ||
269 (std::string(stacktrace[frame]).find(
"deal_II_exceptions") !=
274 const unsigned int first_significant_frame = frame;
277 out <<
'#' << frame - first_significant_frame <<
" ";
282 std::string stacktrace_entry(stacktrace[frame]);
283 const unsigned int pos_start = stacktrace_entry.find(
'('),
284 pos_end = stacktrace_entry.find(
'+');
285 std::string functionname =
286 stacktrace_entry.substr(pos_start + 1, pos_end - pos_start - 1);
288 std::string demangled_stacktrace_entry =
289 stacktrace_entry.substr(0, pos_start);
290 demangled_stacktrace_entry +=
": ";
296#ifdef DEAL_II_HAVE_LIBSTDCXX_DEMANGLER
299 abi::__cxa_demangle(functionname.c_str(),
nullptr,
nullptr, &status);
301 if ((status == 0) && (functionname !=
"main"))
303 std::string realname(p);
310 while (realname.find(
", boost::tuples::null_type>") !=
312 realname.erase(realname.find(
", boost::tuples::null_type>"),
313 std::string(
", boost::tuples::null_type").size());
315 demangled_stacktrace_entry += realname;
318 demangled_stacktrace_entry += functionname;
324 demangled_stacktrace_entry += functionname;
328 out << demangled_stacktrace_entry << std::endl;
331 if (functionname ==
"main")
336 stacktrace =
nullptr;
349 std::ostringstream converter;
351 converter << std::endl
352 <<
"--------------------------------------------------------"
362 std::ostringstream message;
365 const auto message_in_lines =
369 for (
const auto &
line : message_in_lines)
370 converter <<
" " <<
line <<
'\n';
380 <<
"--------------------------------------------------------"
386 converter <<
"--------------------------------------------------------"
394 what_str =
"ExceptionBase::generate_message () failed";
402#ifdef DEAL_II_WITH_MPI
404 : error_code(error_code)
410 char error_name[MPI_MAX_ERROR_STRING];
411 error_name[0] =
'\0';
412 int resulting_length = MPI_MAX_ERROR_STRING;
414 bool error_name_known =
false;
422 int ierr = MPI_Error_class(
error_code, &error_class);
423 error_name_known = (ierr == MPI_SUCCESS);
427 if (error_name_known)
429 ierr = MPI_Error_string(error_class, error_name, &resulting_length);
430 error_name_known = error_name_known && (ierr == MPI_SUCCESS);
434 out <<
"deal.II encountered an error while calling an MPI function."
436 if (error_name_known)
438 out <<
"The description of the error provided by MPI is \""
439 << error_name <<
"\"." << std::endl;
444 <<
"This error code is not equal to any of the standard MPI error codes."
447 out <<
"The numerical value of the original error code is " <<
error_code
454#ifdef DEAL_II_TRILINOS_WITH_SEACAS
456 : error_code(error_code)
460 static_assert(EX_NOERR == 0,
461 "EX_NOERR is assumed to be zero in all versions of ExodusII");
469 out <<
"Error code is " <<
error_code <<
'\n';
470 out <<
"String description: " << ex_strerror(
error_code) <<
'\n';
483 std::cerr << exc.what() << std::endl;
497#ifdef DEAL_II_WITH_MPI
499 MPI_Initialized(&is_initialized);
500 if (is_initialized != 0)
508 <<
"Calling MPI_Abort now.\n"
509 <<
"To break execution in a GDB session, execute 'break MPI_Abort' before "
510 <<
"running. You can also put the following into your ~/.gdbinit:\n"
511 <<
" set breakpoint pending on\n"
512 <<
" break MPI_Abort\n"
513 <<
" set breakpoint pending auto" << std::endl;
515 MPI_Abort(MPI_COMM_WORLD,
525#if KOKKOS_VERSION < 30200
526 if constexpr (std::is_same_v<Kokkos::DefaultExecutionSpace,
527 Kokkos::DefaultHostExecutionSpace>)
538 "Abort() was called during dealing with an assertion or exception.");
553 deallog <<
"Exception: " << exc.get_exc_name() << std::endl;
554 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_NAMESPACE_CLOSE
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()