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 disabled.
10#endif
11
12#include <boost/throw_exception.hpp>
13#include <boost/exception/info.hpp>
14#include <boost/exception/diagnostic_information.hpp>
15#include <boost/core/lightweight_test.hpp>
16#include <stdlib.h>
17
18struct
19my_exception:
20 boost::exception,
21 std::exception
22 {
23 char const *
24 what() const BOOST_NOEXCEPT_OR_NOTHROW
25 {
26 return "my_exception";
27 }
28 };
29
30typedef boost::error_info<struct my_tag,int> my_int;
31
32bool called=false;
33
34namespace
35boost
36 {
37 void
38 throw_exception( std::exception const & x )
39 {
40 called=true;
41 std::string s=boost::diagnostic_information(e: x);
42 std::cout << s;
43#ifndef BOOST_NO_RTTI
44 BOOST_TEST(s.find("my_tag")!=std::string::npos);
45#endif
46 exit(status: boost::report_errors());
47 }
48 void
49 throw_exception(std::exception const & x, boost::source_location const &)
50 {
51 throw_exception(x);
52 }
53 }
54
55int
56main()
57 {
58 BOOST_THROW_EXCEPTION( my_exception() << my_int(42) );
59 BOOST_TEST(called);
60 return boost::report_errors();
61 }
62

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