<!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"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <title>libsigc++: exception_catch()</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">libsigc++  <span id="projectnumber">2.2.11</span> </div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.1.1 --> <div id="navrow1" 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><!-- top --> <div class="header"> <div class="headertitle"> <div class="title">exception_catch()</div> </div> <div class="ingroups"><a class="el" href="group__adaptors.html">Adaptors</a></div></div><!--header--> <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> <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="section user"><dt>Examples:</dt><dd><div class="fragment"><div class="line"> <span class="keyword">struct </span>my_catch</div> <div class="line"> {</div> <div class="line"> <span class="keywordtype">int</span> operator()()</div> <div class="line"> {</div> <div class="line"> <span class="keywordflow">try</span> { <span class="keywordflow">throw</span>; }</div> <div class="line"> <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/a00915.html">std::range_error</a> e) <span class="comment">// catch what types we know</span></div> <div class="line"> { <a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01622.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/a00934.html#a45f5b9c4b7141ac429bf6ea99a7ff6bf">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/a01622.html#a8b3758bb8f17c440c7963363f42f69f3">std::endl</a>; }</div> <div class="line"> <span class="keywordflow">return</span> 1;</div> <div class="line"> }</div> <div class="line"> }</div> <div class="line"> <span class="keywordtype">int</span> foo(); <span class="comment">// throws std::range_error</span></div> <div class="line"> sigc::exception_catch(&foo, my_catch())();</div> </div><!-- fragment --></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="section user"><dt>Example:</dt><dd><div class="fragment"><div class="line"> <a class="code" href="classsigc_1_1signal.html" title="Convenience wrapper for the numbered sigc::signal# templates.">sigc::signal<int></a> some_signal;</div> <div class="line"> 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));</div> </div><!-- fragment --> </dd></dl> </div><!-- contents --> <!-- start footer part --> <hr class="footer"/><address class="footer"><small> Generated by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.8.1.1 </small></address> </body> </html>