<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>libsigc++: exception_catch()</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.2 --> <div class="navigation" id="top"> <div class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> </ul> </div> </div> <div class="header"> <div class="headertitle"> <h1>exception_catch()<br/> <small> [<a class="el" href="group__adaptors.html">Adaptors</a>]</small> </h1> </div> </div> <div class="contents"> <p>sigc::exception_catch() catches an exception thrown from within the wrapped functor and directs it to a catcher functor. <a href="#_details">More...</a></p> <table class="memberdecls"> </table> <p>sigc::exception_catch() catches an exception thrown from within the wrapped functor and directs it to a catcher functor. </p> <p>This catcher can then rethrow the exception and catch it with the proper type.</p> <p>Note that the catcher is expected to return the same type as the wrapped functor so that normal flow can continue.</p> <p>Catchers can be cascaded to catch multiple types, because uncaught rethrown exceptions proceed to the next catcher adaptor.</p> <dl class="user"><dt><b>Examples:</b></dt><dd><div class="fragment"><pre class="fragment"> <span class="keyword">struct </span>my_catch { <span class="keywordtype">int</span> operator()() { <span class="keywordflow">try</span> { <span class="keywordflow">throw</span>; } <span class="keywordflow">catch</span> (<a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00668.html">std::range_error</a> e) <span class="comment">// catch what types we know</span> { <a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01134.html#a7431d56d1e8cd7a9b854171294bd71c7">std::cerr</a> << <span class="stringliteral">"caught "</span> << e.<a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00693.html#ae3ab99c81fd42c6d1db9d9e42b3eddde">what</a>() << <a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01134.html#a9e2ba1ed9813a1f03adc9a87dbf491a5">std::endl</a>; } <span class="keywordflow">return</span> 1; } } <span class="keywordtype">int</span> foo(); <span class="comment">// throws std::range_error</span> sigc::exception_catch(&foo, my_catch())(); </pre></div></dd></dl> <p>The functor sigc::exception_catch() returns can be directly passed into <a class="el" href="classsigc_1_1signal7.html#adc55ac9b0f935fd87a67904022e03cb2" title="Add a slot to the list of slots.">sigc::signal::connect()</a>.</p> <dl class="user"><dt><b>Example:</b></dt><dd><div class="fragment"><pre class="fragment"> <a class="code" href="classsigc_1_1signal.html" title="Convenience wrapper for the numbered sigc::signal# templates.">sigc::signal<int></a> some_signal; some_signal.<a class="code" href="classsigc_1_1signal7.html#adc55ac9b0f935fd87a67904022e03cb2" title="Add a slot to the list of slots.">connect</a>(sigc::exception_catch(&foo, my_catch)); </pre></div> </dd></dl> </div> <hr class="footer"/><address class="footer"><small>Generated on Tue Mar 8 2011 11:44:40 for libsigc++ by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address> </body> </html>