Files
exception/doc/logging.html

61 lines
3.8 KiB
HTML
Raw Normal View History

2008-03-04 01:41:17 +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'/>
<title>Tutorial: Logging of boost::exception Objects</title>
<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">
<a href="http://www.boost.org"><img style="border:0" src="http://www.boost.org/boost.png" alt="Boost" width="277" height="86"/></a>
</div>
<h1>Boost Exception</h1>
</div>
<div class="RenoIncludeDIV"><h2>Logging of boost::exception Objects</h2>
<p>Class <tt>boost::<span class="RenoLink"><a href="exception.html">exception</a></span></tt> provides a virtual member function <tt><span class="RenoLink"><a href="exception_what.html">what</a></span>()</tt>, with a signature identical to the familiar <tt>std::exception::what()</tt> function. The default implementation returns a string value that is not presentable as a friendly user message, but because it is generated automatically, it is useful for debugging or logging purposes. Here is an example:</p>
<pre>#include &lt;<span class="RenoLink"><a href="exception_hpp.html">boost/exception.hpp</a></span>&gt;
#include &lt;iostream&gt;
void f(); //throws unknown types that derive from boost::<span class="RenoLink"><a href="exception.html">exception</a></span>.
void
g()
{
try
{
f();
}
catch(
boost::<span class="RenoLink"><a href="exception.html">exception</a></span> &amp; e )
{
std::cerr &lt;&lt; e.<span class="RenoLink"><a href="exception_what.html">what</a></span>();
}
}</pre>
<p>The <tt><span class="RenoLink"><a href="exception_what.html">what</a></span>()</tt> member function iterates over all data objects stored in the <tt>boost::<span class="RenoLink"><a href="exception.html">exception</a></span></tt> through <tt><span class="RenoLink"><a href="operator_shl_exception.html">operator&lt;&lt;</a></span>()</tt>. The returned string is constructed by converting each data object to string and then concatenating these strings together.</p>
<p>When the <tt><span class="RenoLink"><a href="error_info.html">error_info</a></span>&lt;Tag,T&gt;</tt> template is instantiated, the system attempts overload resolution for an unqualified call to <tt>to_string(x)</tt>, where <tt>x</tt> is of type <tt>T</tt>. If this is successful, the <tt>to_string()</tt> overload is used to convert objects of type <tt>T</tt> to string.</p>
<p>Otherwise, the system attempts overload resolution for <tt>s &lt;&lt; x</tt>, where <tt>s</tt> is a <tt>std::ostringstream</tt> and <tt>x</tt> is of type <tt>T</tt>. If this is successful, the <tt>operator&lt;&lt;</tt> overload is used to convert objects of type <tt>T</tt> to string.</p>
<p>Otherwise the system is unable to convert objects of type <tt>T</tt> to string, and an unspecified stub string value is used without issuing a compile error.</p>
</div><h3>See also:</h3>
<div class="RenoPageList"><a href="boost-exception.html">Boost Exception<br/>
</a></div>
<div id="footer">
<p>&nbsp;</p>
<hr/>
<p>
<a class="logo" href="http://jigsaw.w3.org/css-validator/validator?uri=http://revergestudios.com/boost-exception/reno.css"><img class="logo_pic" src="valid-css.png" alt="Valid CSS" height="31" width="88"/></a>
<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>
<small>Copyright (c) 2006-2008 by Emil Dotchevski and Reverge Studios, Inc.<br/>
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>