<divclass="RenoIncludeDIV"><h2>Integrating Boost Exception in Existing Exception Class Hierarchies</h2>
<p>Some exception hierarchies can not be modified to make <tt>boost::<spanclass="RenoLink"><ahref="exception.html">exception</a></span></tt> a base type. For this case, the <tt><spanclass="RenoLink"><ahref="enable_error_info.html">enable_error_info</a></span>()</tt> function template can be used to make exception objects derive from <tt>boost::<spanclass="RenoLink"><ahref="exception.html">exception</a></span></tt> anyway. Here is an example:</p>
throw boost::<spanclass="RenoLink"><ahref="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>
<p><tt><spanclass="RenoLink"><ahref="enable_error_info.html">Enable_error_info</a></span><T></tt> returns an object of <i>unspecified type</i> which is guaranteed to derive from both <tt>boost::<spanclass="RenoLink"><ahref="exception.html">exception</a></span></tt> and <tt>T</tt>. This makes it possible to use <tt><spanclass="RenoLink"><ahref="operator_shl_exception.html">operator<<</a></span>()</tt> to store additional information in the exception object. The exception can be intercepted as <tt>T &</tt>, therefore existing exception handling will not break. It can also be intercepted as <tt>boost::<spanclass="RenoLink"><ahref="exception.html">exception</a></span>&</tt>, so that <spanclass="RenoLink"><ahref="transporting_data.html">more information can be added to the exception at a later time</a></span>.</p>