1//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
2
3//Distributed under the Boost Software License, Version 1.0. (See accompanying
4//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#include <boost/config.hpp>
7
8#if defined( BOOST_NO_EXCEPTIONS )
9# error This program requires exception handling.
10#endif
11
12#include "helper1.hpp"
13#include <boost/exception/get_error_info.hpp>
14#include <boost/exception/info.hpp>
15#include <boost/exception/diagnostic_information.hpp>
16#include <boost/detail/lightweight_test.hpp>
17
18namespace
19 {
20 typedef boost::error_info<struct tag_test_int,int> test_int;
21
22 void
23 throw_wrapper()
24 {
25 try
26 {
27 boost::exception_test::throw_length_error();
28 }
29 catch(
30 boost::exception & x )
31 {
32 x << test_int(42);
33 throw;
34 }
35 catch(
36 ... )
37 {
38 BOOST_TEST(false);
39 }
40 }
41 }
42
43int
44main()
45 {
46 try
47 {
48 throw_wrapper();
49 BOOST_TEST(false);
50 }
51 catch(
52 std::exception & x )
53 {
54#ifdef BOOST_NO_RTTI
55 try
56 {
57 throw;
58 }
59 catch(
60 boost::exception & x )
61 {
62#endif
63 BOOST_TEST( boost::get_error_info<test_int>(x) );
64 if( int const * p=boost::get_error_info<test_int>(some_exception&: x) )
65 BOOST_TEST( 42==*p );
66#ifdef BOOST_NO_RTTI
67 }
68 catch(
69 ... )
70 {
71 BOOST_TEST(false);
72 }
73#endif
74 BOOST_TEST( std::string(x.what())==std::string("exception test length error") );
75 }
76 catch(
77 ... )
78 {
79 BOOST_TEST(false);
80 }
81 return boost::report_errors();
82 }
83

source code of boost/libs/exception/test/enable_error_info_test.cpp