Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_StandardCatchMacros.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TEUCHOS_STANDARD_CATCH_MACROS_HPP
11 #define TEUCHOS_STANDARD_CATCH_MACROS_HPP
12 
14 #include "Teuchos_FancyOStream.hpp"
16 #include "Teuchos_stacktrace.hpp"
17 #include "Teuchos_Assert.hpp"
18 
19 
20 #ifdef HAVE_TEUCHOS_STACKTRACE
21 # define TEUCHOS_GET_STORED_STACKTRACE() \
22  (Teuchos::TestForException_getEnableStacktrace() \
23  ? Teuchos::get_stored_stacktrace() + "\n" \
24  : std::string() )
25 #else
26 # define TEUCHOS_GET_STORED_STACKTRACE() ""
27 #endif
28 
29 
33 #define TEUCHOS_STANDARD_CATCH_STATEMENTS_IMPL(VERBOSE, ERR_STREAM, \
34  SHOW_STACK_TRACE, SUCCESS_FLAG \
35  ) \
36  catch (const std::exception &excpt) { \
37  if((VERBOSE)) { \
38  std::ostringstream oss; \
39  oss \
40  << "\np="<<::Teuchos::GlobalMPISession::getRank() \
41  <<": *** Caught standard std::exception of type \'" \
42  <<Teuchos::concreteTypeName(excpt)<<"\' :\n\n"; \
43  Teuchos::OSTab scsi_tab(oss); \
44  if (SHOW_STACK_TRACE) { \
45  scsi_tab.o() << TEUCHOS_GET_STORED_STACKTRACE(); \
46  } \
47  scsi_tab.o() << excpt.what() << std::endl; \
48  (ERR_STREAM) << std::flush; \
49  (ERR_STREAM) << oss.str(); \
50  (SUCCESS_FLAG) = false; \
51  } \
52  } \
53  catch (const int &excpt_code) { \
54  if((VERBOSE)) { \
55  std::ostringstream oss; \
56  oss \
57  << "\np="<<::Teuchos::GlobalMPISession::getRank() \
58  << ": *** Caught an integer exception with value = " \
59  << excpt_code << std::endl; \
60  (ERR_STREAM) << std::flush; \
61  (ERR_STREAM) << oss.str(); \
62  (SUCCESS_FLAG) = false; \
63  } \
64  } \
65  catch ( ... ) { \
66  if ((VERBOSE)) { \
67  std::ostringstream oss; \
68  oss << "\np="<<::Teuchos::GlobalMPISession::getRank() \
69  <<": *** Caught an unknown exception\n"; \
70  (ERR_STREAM) << std::flush; \
71  (ERR_STREAM) << oss.str(); \
72  (SUCCESS_FLAG) = false; \
73  } \
74  }
75 
76 
77 
104 #define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG) \
105  TEUCHOS_STANDARD_CATCH_STATEMENTS_IMPL(VERBOSE, ERR_STREAM, true, SUCCESS_FLAG)
106 
107 
108 #endif // TEUCHOS_STANDARD_CATCH_MACROS_HPP
Functions for returning stacktrace info (GCC only initially).
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Defines basic traits returning the name of a type in a portable and readable way. ...