• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //This example shows how to add data to boost::exception objects at the
7 //point of the throw, and how to retrieve that data at the point of the catch.
8 
9 #include <boost/exception/all.hpp>
10 #include <iostream>
11 
12 typedef boost::error_info<struct tag_my_info,int> my_info; //(1)
13 
14 struct my_error: virtual boost::exception, virtual std::exception { }; //(2)
15 
16 void
f()17 f()
18     {
19     throw my_error() << my_info(42); //(3)
20     }
21 
22 void
g()23 g()
24     {
25     try
26         {
27         f();
28         }
29     catch(
30     my_error & x )
31         {
32         if( int const * mi=boost::get_error_info<my_info>(x) )
33             std::cerr << "My info: " << *mi;
34         }
35     }
36