libsigcplusplus/docs/reference/html/group__exception__catch.html

65 lines
5.4 KiB
HTML

<!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"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<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" />
<link href="doxygen-extra.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 id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">libsigc++
&#160;<span id="projectnumber">2.10.3</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li class="current"><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 class="ingroups"><a class="el" href="group__adaptors.html">Adaptors</a></div></div> </div>
</div><!--header-->
<div class="contents">
<p><a class="el" href="namespacesigc.html#a0ae3b8a1ba26920cee4d7d9df2c39ed9">sigc::exception_catch()</a> catches an exception thrown from within the wrapped functor and directs it to a catcher functor.
<a href="#details">More...</a></p>
<p><a class="el" href="namespacesigc.html#a0ae3b8a1ba26920cee4d7d9df2c39ed9">sigc::exception_catch()</a> 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/a02924.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/a01544.html#a7431d56d1e8cd7a9b854171294bd71c7">std::cerr</a> &lt;&lt; <span class="stringliteral">&quot;caught &quot;</span> &lt;&lt; e.<a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a02920.html#a261a33056182b4b5f047e7061d716380">what</a>() &lt;&lt; <a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01544.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"><a class="code" href="namespacesigc.html#a0ae3b8a1ba26920cee4d7d9df2c39ed9">sigc::exception_catch</a>(&amp;foo, my_catch())();</div></div><!-- fragment --></dd></dl>
<p>The functor <a class="el" href="namespacesigc.html#a0ae3b8a1ba26920cee4d7d9df2c39ed9">sigc::exception_catch()</a> 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">sigc::signal&lt;int&gt;</a> some_signal;</div><div class="line">some_signal.<a class="code" href="classsigc_1_1signal7.html#adc55ac9b0f935fd87a67904022e03cb2">connect</a>(<a class="code" href="namespacesigc.html#a0ae3b8a1ba26920cee4d7d9df2c39ed9">sigc::exception_catch</a>(&amp;foo, my_catch));</div></div><!-- fragment --> </dd></dl>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Mar 25 2020 10:13:27 for libsigc++ by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.11
</small></address>
</body>
</html>