File indexing completed on 2025-01-30 09:35:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef BOOST_CATCH_EXCEPTIONS_HPP
0017 #define BOOST_CATCH_EXCEPTIONS_HPP
0018
0019
0020
0021 #include <string> // for string
0022 #include <new> // for bad_alloc
0023 #include <ostream> // for ostream
0024 #include <typeinfo> // for bad_cast, bad_typeid
0025 #include <exception> // for exception, bad_exception
0026 #include <stdexcept> // for std exception hierarchy
0027 #include <boost/config.hpp>
0028 #include <boost/cstdlib.hpp> // for exit codes
0029
0030 # if defined(BOOST_BORLANDC) && (__BORLANDC__ <= 0x0551)
0031 # define BOOST_BUILT_IN_EXCEPTIONS_MISSING_WHAT
0032 # endif
0033
0034 #if defined(MPW_CPLUS) && (MPW_CPLUS <= 0x890)
0035 # define BOOST_BUILT_IN_EXCEPTIONS_MISSING_WHAT
0036 namespace std { class bad_typeid { }; }
0037 # endif
0038
0039 namespace boost
0040 {
0041
0042 namespace detail
0043 {
0044
0045 inline void report_exception( std::ostream & os,
0046 const char * name, const char * info )
0047 { os << "\n** uncaught exception: " << name << " " << info << std::endl; }
0048 }
0049
0050
0051
0052 template< class Generator >
0053 int catch_exceptions( Generator function_object,
0054 std::ostream & out, std::ostream & err )
0055 {
0056 int result = 0;
0057 bool exception_thrown = true;
0058
0059 #ifndef BOOST_NO_EXCEPTIONS
0060 try
0061 {
0062 #endif
0063 result = function_object();
0064 exception_thrown = false;
0065 #ifndef BOOST_NO_EXCEPTIONS
0066 }
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 catch ( const char * ex )
0077 { detail::report_exception( out, "", ex ); }
0078 catch ( const std::string & ex )
0079 { detail::report_exception( out, "", ex.c_str() ); }
0080
0081
0082 catch ( const std::bad_alloc & ex )
0083 { detail::report_exception( out, "std::bad_alloc:", ex.what() ); }
0084
0085 # ifndef BOOST_BUILT_IN_EXCEPTIONS_MISSING_WHAT
0086 catch ( const std::bad_cast & ex )
0087 { detail::report_exception( out, "std::bad_cast:", ex.what() ); }
0088 catch ( const std::bad_typeid & ex )
0089 { detail::report_exception( out, "std::bad_typeid:", ex.what() ); }
0090 # else
0091 catch ( const std::bad_cast & )
0092 { detail::report_exception( out, "std::bad_cast", "" ); }
0093 catch ( const std::bad_typeid & )
0094 { detail::report_exception( out, "std::bad_typeid", "" ); }
0095 # endif
0096
0097 catch ( const std::bad_exception & ex )
0098 { detail::report_exception( out, "std::bad_exception:", ex.what() ); }
0099 catch ( const std::domain_error & ex )
0100 { detail::report_exception( out, "std::domain_error:", ex.what() ); }
0101 catch ( const std::invalid_argument & ex )
0102 { detail::report_exception( out, "std::invalid_argument:", ex.what() ); }
0103 catch ( const std::length_error & ex )
0104 { detail::report_exception( out, "std::length_error:", ex.what() ); }
0105 catch ( const std::out_of_range & ex )
0106 { detail::report_exception( out, "std::out_of_range:", ex.what() ); }
0107 catch ( const std::range_error & ex )
0108 { detail::report_exception( out, "std::range_error:", ex.what() ); }
0109 catch ( const std::overflow_error & ex )
0110 { detail::report_exception( out, "std::overflow_error:", ex.what() ); }
0111 catch ( const std::underflow_error & ex )
0112 { detail::report_exception( out, "std::underflow_error:", ex.what() ); }
0113 catch ( const std::logic_error & ex )
0114 { detail::report_exception( out, "std::logic_error:", ex.what() ); }
0115 catch ( const std::runtime_error & ex )
0116 { detail::report_exception( out, "std::runtime_error:", ex.what() ); }
0117 catch ( const std::exception & ex )
0118 { detail::report_exception( out, "std::exception:", ex.what() ); }
0119
0120 catch ( ... )
0121 { detail::report_exception( out, "unknown exception", "" ); }
0122 #endif
0123
0124 if ( exception_thrown ) result = boost::exit_exception_failure;
0125
0126 if ( result != 0 && result != exit_success )
0127 {
0128 out << std::endl << "**** returning with error code "
0129 << result << std::endl;
0130 err
0131 << "********** errors detected; see stdout for details ***********"
0132 << std::endl;
0133 }
0134 #if !defined(BOOST_NO_CPP_MAIN_SUCCESS_MESSAGE)
0135 else { out << std::flush << "no errors detected" << std::endl; }
0136 #endif
0137 return result;
0138 }
0139
0140 }
0141
0142 #endif
0143