• 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 throw exception objects that support
7 //transporting of arbitrary data to the catch site, even for types
8 //that do not derive from boost::exception.
9 
10 #include <boost/exception/all.hpp>
11 #include <stdexcept>
12 
13 typedef boost::error_info<struct tag_std_range_min,size_t> std_range_min;
14 typedef boost::error_info<struct tag_std_range_max,size_t> std_range_max;
15 typedef boost::error_info<struct tag_std_range_index,size_t> std_range_index;
16 
17 template <class T>
18 class
19 my_container
20     {
21     public:
22 
23     size_t size() const;
24 
25     T const &
operator [](size_t i) const26     operator[]( size_t i ) const
27         {
28         if( i > size() )
29             throw boost::enable_error_info(std::range_error("Index out of range")) <<
30                 std_range_min(0) <<
31                 std_range_max(size()) <<
32                 std_range_index(i);
33         //....
34         }
35     };
36