2008-06-28 18:29:40 +00:00
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
< html xmlns = 'http://www.w3.org/1999/xhtml' xml:lang = 'en' lang = 'en' >
< head >
< meta http-equiv = 'Content-Type' content = 'text/html; charset=utf-8' />
2008-07-16 21:03:14 +00:00
< title > integrating boost exception in existing exception class hierarchies</ title >
2008-06-28 18:29:40 +00:00
< link href = 'reno.css' type = 'text/css' rel = 'stylesheet' />
</ head >
< body >
< div class = "body-0" >
< div class = "body-1" >
< div class = "body-2" >
< div >
< div id = "boost_logo" >
2009-05-16 13:45:21 +00:00
< a href = "http://www.boost.org" >< img style = "border:0" src = "../../../boost.png" alt = "Boost" width = "277" height = "86" /></ a >
2008-06-28 18:29:40 +00:00
</ div >
< h1 > Boost Exception</ h1 >
</ div >
2009-04-02 05:04:38 +00:00
<!-- Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. -->
2008-06-28 18:29:40 +00:00
<!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
2008-07-16 21:03:14 +00:00
< div class = "RenoIncludeDIV" >< div class = "RenoAutoDIV" >< h2 > Integrating Boost Exception in Existing Exception Class Hierarchies</ h2 >
2008-07-09 00:39:00 +00:00
</ div >
< p > Some exception hierarchies can not be modified to make boost::< span class = "RenoLink" >< a href = "exception.html" > exception</ a ></ span > a base type. In this case, the < span class = "RenoLink" >< a href = "enable_error_info.html" > enable_error_info</ a ></ span > function template can be used to make exception objects derive from boost::< span class = "RenoLink" >< a href = "exception.html" > exception</ a ></ span > anyway. Here is an example:</ p >
2009-07-22 20:55:50 +00:00
< pre > #include < < span class = "RenoLink" >< a href = "boost_exception_all_hpp.html" > boost/exception/all.hpp</ a ></ span > >
2008-06-28 18:29:40 +00:00
#include < stdexcept>
typedef boost::< span class = "RenoLink" >< a href = "error_info.html" > error_info</ a ></ span > < struct tag_std_range_min,size_t> std_range_min;
typedef boost::< span class = "RenoLink" >< a href = "error_info.html" > error_info</ a ></ span > < struct tag_std_range_max,size_t> std_range_max;
typedef boost::< span class = "RenoLink" >< a href = "error_info.html" > error_info</ a ></ span > < struct tag_std_range_index,size_t> std_range_index;
template < class T>
class
my_container
{
public:
size_t size() const;
T const &
operator[]( size_t i ) const
{
if( i > size() )
throw boost::< span class = "RenoLink" >< a href = "enable_error_info.html" > enable_error_info</ a ></ span > (std::range_error("Index out of range")) <<
std_range_min(0) <<
std_range_max(size()) <<
std_range_index(i);
//....
}
};
</ pre >
2008-09-19 20:29:26 +00:00
< p > The call to < span class = "RenoLink" >< a href = "enable_error_info.html" > enable_error_info</ a ></ span > < T> gets us an object of < i > unspecified type</ i > which is guaranteed to derive from both boost::< span class = "RenoLink" >< a href = "exception.html" > exception</ a ></ span > and T. This makes it possible to use < span class = "RenoLink" >< a href = "exception_operator_shl.html" > operator<< </ a ></ span > to store additional information in the exception object. The exception can be intercepted as T & , so existing exception handling will not break. It can also be intercepted as boost::< span class = "RenoLink" >< a href = "exception.html" > exception</ a ></ span > & , so that < span class = "RenoLink" >< a href = "tutorial_transporting_data.html" > more information can be added to the exception at a later time</ a ></ span > .</ p >
2008-07-09 00:39:00 +00:00
</ div >< div class = "RenoAutoDIV" >< div class = "RenoHR" >< hr /></ div >
< h3 > See Also:</ h3 >
2008-06-28 18:29:40 +00:00
< div class = "RenoPageList" >< a href = "boost-exception.html" > Boost Exception< br />
2009-03-31 22:16:49 +00:00
</ a >< a href = "motivation.html" > Motivation< br />
2008-06-28 18:29:40 +00:00
</ a ></ div >
2008-07-09 00:39:00 +00:00
</ div >
2009-04-02 05:04:38 +00:00
<!-- Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. -->
2008-06-28 18:29:40 +00:00
<!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
< div id = "footer" >
< p > </ p >
< hr />
< p >
2009-03-29 05:04:54 +00:00
< a class = "logo" href = "http://jigsaw.w3.org/css-validator/check/referer" >< img class = "logo_pic" src = "valid-css.png" alt = "Valid CSS" height = "31" width = "88" /></ a >
2008-06-28 18:29:40 +00:00
< a class = "logo" href = "http://validator.w3.org/check?uri=referer" >< img class = "logo_pic" src = "valid-xhtml.png" alt = "Valid XHTML 1.0" height = "31" width = "88" /></ a >
2009-04-02 05:04:38 +00:00
< small > Copyright (c) 2006-2009 by Emil Dotchevski and Reverge Studios, Inc.< br />
2008-06-28 18:29:40 +00:00
Distributed under the < a href = "http://www.boost.org/LICENSE_1_0.txt" > Boost Software License, Version 1.0</ a > .</ small >
</ p >
</ div >
</ div >
</ div >
</ div >
</ body >
</ html >