enable_error_info_test.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 "helper1.hpp"
  5. #include <boost/exception/get_error_info.hpp>
  6. #include <boost/exception/info.hpp>
  7. #include <boost/exception/diagnostic_information.hpp>
  8. #include <boost/detail/lightweight_test.hpp>
  9. namespace
  10. {
  11. typedef boost::error_info<struct tag_test_int,int> test_int;
  12. void
  13. throw_wrapper()
  14. {
  15. try
  16. {
  17. boost::exception_test::throw_length_error();
  18. }
  19. catch(
  20. boost::exception & x )
  21. {
  22. x << test_int(42);
  23. throw;
  24. }
  25. catch(
  26. ... )
  27. {
  28. BOOST_TEST(false);
  29. }
  30. }
  31. }
  32. int
  33. main()
  34. {
  35. try
  36. {
  37. throw_wrapper();
  38. BOOST_TEST(false);
  39. }
  40. catch(
  41. std::exception & x )
  42. {
  43. #ifdef BOOST_NO_RTTI
  44. try
  45. {
  46. throw;
  47. }
  48. catch(
  49. boost::exception & x )
  50. {
  51. #endif
  52. BOOST_TEST( boost::get_error_info<test_int>(x) );
  53. if( int const * p=boost::get_error_info<test_int>(x) )
  54. BOOST_TEST( 42==*p );
  55. #ifdef BOOST_NO_RTTI
  56. }
  57. catch(
  58. ... )
  59. {
  60. BOOST_TEST(false);
  61. }
  62. #endif
  63. BOOST_TEST( std::string(x.what())==std::string("exception test length error") );
  64. }
  65. catch(
  66. ... )
  67. {
  68. BOOST_TEST(false);
  69. }
  70. return boost::report_errors();
  71. }