123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- #ifndef BOOST_CATCH_EXCEPTIONS_HPP
- #define BOOST_CATCH_EXCEPTIONS_HPP
- #include <string>
- #include <new>
- #include <typeinfo>
- #include <exception>
- #include <stdexcept>
- #include <boost/cstdlib.hpp>
- # if __GNUC__ != 2 || __GNUC_MINOR__ > 96
- # include <ostream>
- # else
- # include <iostream>
- # endif
- # if defined(__BORLANDC__) && (__BORLANDC__ <= 0x0551)
- # define BOOST_BUILT_IN_EXCEPTIONS_MISSING_WHAT
- # endif
- #if defined(MPW_CPLUS) && (MPW_CPLUS <= 0x890)
- # define BOOST_BUILT_IN_EXCEPTIONS_MISSING_WHAT
- namespace std { class bad_typeid { }; }
- # endif
- namespace boost
- {
- namespace detail
- {
-
- inline void report_exception( std::ostream & os,
- const char * name, const char * info )
- { os << "\n** uncaught exception: " << name << " " << info << std::endl; }
- }
-
- template< class Generator >
- int catch_exceptions( Generator function_object,
- std::ostream & out, std::ostream & err )
- {
- int result = 0;
- bool exception_thrown = true;
- #ifndef BOOST_NO_EXCEPTIONS
- try
- {
- #endif
- result = function_object();
- exception_thrown = false;
- #ifndef BOOST_NO_EXCEPTIONS
- }
-
-
-
-
-
-
- catch ( const char * ex )
- { detail::report_exception( out, "", ex ); }
- catch ( const std::string & ex )
- { detail::report_exception( out, "", ex.c_str() ); }
-
- catch ( const std::bad_alloc & ex )
- { detail::report_exception( out, "std::bad_alloc:", ex.what() ); }
- # ifndef BOOST_BUILT_IN_EXCEPTIONS_MISSING_WHAT
- catch ( const std::bad_cast & ex )
- { detail::report_exception( out, "std::bad_cast:", ex.what() ); }
- catch ( const std::bad_typeid & ex )
- { detail::report_exception( out, "std::bad_typeid:", ex.what() ); }
- # else
- catch ( const std::bad_cast & )
- { detail::report_exception( out, "std::bad_cast", "" ); }
- catch ( const std::bad_typeid & )
- { detail::report_exception( out, "std::bad_typeid", "" ); }
- # endif
- catch ( const std::bad_exception & ex )
- { detail::report_exception( out, "std::bad_exception:", ex.what() ); }
- catch ( const std::domain_error & ex )
- { detail::report_exception( out, "std::domain_error:", ex.what() ); }
- catch ( const std::invalid_argument & ex )
- { detail::report_exception( out, "std::invalid_argument:", ex.what() ); }
- catch ( const std::length_error & ex )
- { detail::report_exception( out, "std::length_error:", ex.what() ); }
- catch ( const std::out_of_range & ex )
- { detail::report_exception( out, "std::out_of_range:", ex.what() ); }
- catch ( const std::range_error & ex )
- { detail::report_exception( out, "std::range_error:", ex.what() ); }
- catch ( const std::overflow_error & ex )
- { detail::report_exception( out, "std::overflow_error:", ex.what() ); }
- catch ( const std::underflow_error & ex )
- { detail::report_exception( out, "std::underflow_error:", ex.what() ); }
- catch ( const std::logic_error & ex )
- { detail::report_exception( out, "std::logic_error:", ex.what() ); }
- catch ( const std::runtime_error & ex )
- { detail::report_exception( out, "std::runtime_error:", ex.what() ); }
- catch ( const std::exception & ex )
- { detail::report_exception( out, "std::exception:", ex.what() ); }
- catch ( ... )
- { detail::report_exception( out, "unknown exception", "" ); }
- #endif
- if ( exception_thrown ) result = boost::exit_exception_failure;
- if ( result != 0 && result != exit_success )
- {
- out << std::endl << "**** returning with error code "
- << result << std::endl;
- err
- << "********** errors detected; see stdout for details ***********"
- << std::endl;
- }
- #if !defined(BOOST_NO_CPP_MAIN_SUCCESS_MESSAGE)
- else { out << std::flush << "no errors detected" << std::endl; }
- #endif
- return result;
- }
- }
- #endif
|