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") !=
nullptr)
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);
247 stacktrace_entry = stacktrace_entry.substr(0, pos_start);
248 stacktrace_entry +=
": ";
254 #ifdef DEAL_II_HAVE_LIBSTDCXX_DEMANGLER 256 char *p = abi::__cxa_demangle(functionname.c_str(),
nullptr,
nullptr, &status);
258 if ((status == 0) && (functionname !=
"main"))
260 std::string realname(p);
267 while (realname.find (
", boost::tuples::null_type>")
268 != std::string::npos)
269 realname.erase (realname.find (
", boost::tuples::null_type>"),
270 std::string (
", boost::tuples::null_type").size());
272 stacktrace_entry += realname;
275 stacktrace_entry += functionname;
281 stacktrace_entry += functionname;
285 out << stacktrace_entry
289 if (functionname ==
"main")
303 std::ostringstream converter;
305 converter << std::endl
306 <<
"--------------------------------------------------------" 315 if (!deal_II_exceptions::additional_assert_output.empty())
317 converter <<
"--------------------------------------------------------" 319 << deal_II_exceptions::additional_assert_output
323 converter <<
"--------------------------------------------------------" 331 what_str =
"ExceptionBase::generate_message () failed";
337 #ifdef DEAL_II_WITH_MPI 340 ExcMPI::ExcMPI (
const int error_code)
342 error_code (error_code)
345 void ExcMPI::print_info (std::ostream &out)
const 347 char error_name[MPI_MAX_ERROR_STRING];
348 error_name[0] =
'\0';
349 int resulting_length = MPI_MAX_ERROR_STRING;
351 bool error_name_known =
false;
354 if (error_code < MPI_ERR_LASTCODE)
359 int ierr = MPI_Error_class (error_code, &error_class);
360 error_name_known = (ierr == MPI_SUCCESS);
364 if (error_name_known)
366 ierr = MPI_Error_string (error_class, error_name, &resulting_length);
367 error_name_known = error_name_known && (ierr == MPI_SUCCESS);
371 out <<
"deal.II encountered an error while calling an MPI function." 373 if (error_name_known)
375 out <<
"The description of the error provided by MPI is \"" 382 out <<
"This error code is not equal to any of the standard MPI error codes." 385 out <<
"The numerical value of the original error code is " 391 #endif // DEAL_II_WITH_MPI 399 std::cerr << exc.what() << std::endl;
413 #ifdef DEAL_II_WITH_MPI 415 MPI_Initialized(&is_initialized);
421 MPI_Comm_size (MPI_COMM_WORLD, &n_proc);
424 std::cerr <<
"Calling MPI_Abort now.\n" 425 <<
"To break execution in a GDB session, execute 'break MPI_Abort' before " 426 <<
"running. You can also put the following into your ~/.gdbinit:\n" 427 <<
" set breakpoint pending on\n" 428 <<
" break MPI_Abort\n" 429 <<
" set breakpoint pending auto" << std::endl;
431 MPI_Abort (MPI_COMM_WORLD,
446 if (::deal_II_exceptions::abort_on_exception)
452 deallog <<
"Exception: " << exc.get_exc_name() << std::endl;
453 deallog << exc.what() << std::endl;
462 if (::deal_II_exceptions::abort_on_exception)
473 #ifdef DEAL_II_WITH_CUDA 478 case CUSPARSE_STATUS_NOT_INITIALIZED:
480 return "The cuSPARSE library was not initialized";
482 case CUSPARSE_STATUS_ALLOC_FAILED:
484 return "Resource allocation failed inside the cuSPARSE library";
486 case CUSPARSE_STATUS_INVALID_VALUE:
488 return "An unsupported value of parameter was passed to the function";
490 case CUSPARSE_STATUS_ARCH_MISMATCH:
492 return "The function requires a feature absent from the device architecture";
494 case CUSPARSE_STATUS_MAPPING_ERROR:
496 return "An access to GPU memory space failed";
498 case CUSPARSE_STATUS_EXECUTION_FAILED:
500 return "The GPU program failed to execute";
502 case CUSPARSE_STATUS_INTERNAL_ERROR:
504 return "An internal cuSPARSE operation failed";
506 case CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED:
508 return "The matrix type is not supported by this function";
512 return "Unknown error";
524 case CUSOLVER_STATUS_NOT_INITIALIZED:
526 return "The cuSolver library was not initialized";
528 case CUSOLVER_STATUS_ALLOC_FAILED:
530 return "Resource allocation failed inside the cuSolver library";
532 case CUSOLVER_STATUS_INVALID_VALUE:
534 return "An unsupported value of a parameter was passed to the function";
536 case CUSOLVER_STATUS_ARCH_MISMATCH:
538 return "The function requires a feature absent from the device architecture";
540 case CUSOLVER_STATUS_EXECUTION_FAILED:
542 return "The GPU program failed to execute";
544 case CUSOLVER_STATUS_INTERNAL_ERROR:
546 return "An internal cuSolver operation failed";
548 case CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED:
550 return "The matrix type is not supported by this function";
554 return "Unknown error";
565 DEAL_II_NAMESPACE_CLOSE
577 #ifdef DEAL_II_HAVE_VERBOSE_TERMINATE 580 extern void __verbose_terminate_handler ();
585 struct preload_terminate_dummy
587 preload_terminate_dummy()
589 std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
593 static preload_terminate_dummy dummy;
virtual const char * what() const noexcept
void suppress_stacktrace_in_exceptions()
std::string get_cusolver_error_string(const cusolverStatus_t error_code)
void set_additional_assert_output(const char *const p)
void * raw_stacktrace[25]
virtual void print_info(std::ostream &out) const
void set_fields(const char *file, const int line, const char *function, const char *cond, const char *exc_name)
void do_issue_error_nothrow(const ExceptionBase &e) noexcept
std::string get_cusparse_error_string(const cusparseStatus_t error_code)
void print_stack_trace(std::ostream &out) const
void abort(const ExceptionBase &exc)
void print_exc_data(std::ostream &out) const
void generate_message() const
virtual ~ExceptionBase() noexcept
void disable_abort_on_exception()
const char * get_exc_name() const