throw_exception_test4.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2018 Peter Dimov
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. //
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. #include <boost/throw_exception.hpp>
  8. #include <boost/exception/get_error_info.hpp>
  9. #include <boost/detail/lightweight_test.hpp>
  10. class my_exception: public std::exception
  11. {
  12. };
  13. class my_exception2: public std::exception, public boost::exception
  14. {
  15. };
  16. int main()
  17. {
  18. try
  19. {
  20. BOOST_THROW_EXCEPTION( my_exception() );
  21. }
  22. catch( boost::exception const & x )
  23. {
  24. int const * line = boost::get_error_info<boost::throw_line>( x );
  25. BOOST_TEST( line != 0 );
  26. BOOST_TEST_EQ( *line, 24 );
  27. }
  28. try
  29. {
  30. BOOST_THROW_EXCEPTION( my_exception2() );
  31. }
  32. catch( boost::exception const & x )
  33. {
  34. int const * line = boost::get_error_info<boost::throw_line>( x );
  35. BOOST_TEST( line != 0 );
  36. BOOST_TEST_EQ( *line, 36 );
  37. }
  38. return boost::report_errors();
  39. }