current_exception_cast_test.cpp 920 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include <boost/exception/current_exception_cast.hpp>
  5. #include <boost/detail/lightweight_test.hpp>
  6. #include <exception>
  7. class
  8. my_exception:
  9. public std::exception
  10. {
  11. };
  12. class
  13. polymorphic
  14. {
  15. virtual
  16. ~polymorphic()
  17. {
  18. }
  19. };
  20. int
  21. main()
  22. {
  23. try
  24. {
  25. throw my_exception();
  26. }
  27. catch(
  28. std::exception & e )
  29. {
  30. try
  31. {
  32. throw;
  33. }
  34. catch(
  35. ...)
  36. {
  37. BOOST_TEST(boost::current_exception_cast<std::exception>()==&e);
  38. BOOST_TEST(!boost::current_exception_cast<polymorphic>());
  39. }
  40. }
  41. return boost::report_errors();
  42. }