File: group__exception__catch.html

package info (click to toggle)
libsigc%2B%2B-2.0 2.0.10-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 20,220 kB
  • ctags: 6,376
  • sloc: sh: 8,402; cpp: 1,717; xml: 368; makefile: 364; perl: 51; ansic: 45
file content (52 lines) | stat: -rw-r--r-- 3,015 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>libsigc++ 2.0: exception_catch()</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#ffffff">
<table border="0" width="100%">
<tr>
    <td width="10%" height="40"><img src="../../images/libsigc_logo.gif" alt="logo" border="0" width="100%" height="100%"/></td>
    <td width="90%" height="40"><img src="../../images/top.gif" alt="top" width="100%" height="40"/></td>
</tr>
</table>
<center>
  <a class="qindex" href="../../index.html">Main Page</a> &nbsp;
  <a class="qindex" href="modules.html">Groups</a> &nbsp;
  <a class="qindex" href="namespaces.html"> Namespaces</a> &nbsp;
</center>
<hr width="100%"/>

<!-- Generated by Doxygen 1.3.9.1 -->
<h1>exception_catch()<br>
<small>
[<a class="el" href="group__adaptors.html">Adaptors</a>]</small>
</h1><a class="el" href="namespacesigc.html#a31">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><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
</table>
This catcher can then rethrow the exception and catch it with the proper type.<p>
Note that the catcher is expected to return the same type as the wrapped functor so that normal flow can continue.<p>
Catchers can be cascaded to catch multiple types because uncaught rethrown exceptions proceed to the next catcher adaptor.<p>
<dl compact><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> (std::range_error e) <span class="comment">// catch what types we know</span>
         { std::cerr &lt;&lt; <span class="stringliteral">"caught "</span> &lt;&lt; e.what() &lt;&lt; std::endl; }
       <span class="keywordflow">return</span> 1;
     }
   }
   <span class="keywordtype">int</span> foo(); <span class="comment">// throws std::range_error</span>
   <a class="code" href="namespacesigc.html#a31">sigc::exception_catch</a>(&amp;foo, my_catch())();
</pre></div></dd></dl>
The functor sigc::execption_catch() returns can be passed into <a class="el" href="classsigc_1_1signal7.html#a0">sigc::signal::connect()</a> directly.<p>
<dl compact><dt><b>Example:</b></dt><dd><div class="fragment"><pre class="fragment">   <a class="code" href="classsigc_1_1signal.html">sigc::signal&lt;int&gt;</a> some_signal;
   some_signal.<a class="code" href="classsigc_1_1signal7.html#a0">connect</a>(sigc::exception_catch(&amp;foo, my_catch));
</pre></div></dd></dl>
<hr><address><small>
Generated for libsigc++ 2.0 by <a href="http://www.doxygen.org/index.html">
Doxygen</a> 1.3.9.1 &copy;&nbsp;1997-2001</small></address>
</body>
</html>