Debian Codegraph @

docs/manual/tasks/trycatch.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <title>Ant-contrib Tasks: Trycatch</title>
5 </head>
6
7 <body>
8 <h1>Trycatch</h1>
9
10 <p>A wrapper that lets you run a set of tasks and optionally run a
11 different set of tasks if the first set fails and yet another set
12 after the first one has finished.</p>
13
14 <p>This mirrors Java's try/catch/finally.</p>
15
16 <p>The tasks inside of the required <code>&lt;try&gt;</code>
17 element will be run. If one of them should throw a BuildException
18 several things can happen:</p>
19
20 <ul>
21 <li>If there is no <code>&lt;catch&gt;</code> block, the
22 exception will be passed through to Ant.</li>
23
24 <li>If the property attribute has been set, a property of the
25 given name will be set to the message of the exception.</li>
26
27 <li>If the reference attribute has been set, a reference of the
28 given id will be created and point to the exception object.</li>
29
30 <li>If there is a <code>&lt;catch&gt;</code> block, the tasks
31 nested into it will be run.</li>
32 </ul>
33
34 <p>If a <code>&lt;finally&gt;</code> block is present, the task
35 nested into it will be run, no matter whether the first tasks have
36 thrown an exception or not.</p>
37
38 <h2>Parameters</h2>
39 <table border="1" cellpadding="2" cellspacing="0">
40 <tr>
41 <th>Attribute</th>
42 <th>Description</th>
43 <th>Required</th>
44 </tr>
45 <tr>
46 <td valign="top">property</td>
47 <td valign="top">Name of a property that will receive the
48 message of the exception that has been caught (if any)</td>
49 <td align="center" valign="top">No.</td>
50 </tr>
51 <tr>
52 <td valign="top">reference</td>
53 <td valign="top">Id of a reference that will point to the
54 exception object that has been caught (if any)</td>
55 <td align="center" valign="top">No</td>
56 </tr>
57 </table>
58
59 <h2>Example</h2>
60
61 <pre>
62 &lt;trycatch property=&quot;foo&quot; reference=&quot;bar&quot;&gt;
63 &lt;try&gt;
64 &lt;fail&gt;Tada!&lt;/fail&gt;
65 &lt;/try&gt;
66
67 &lt;catch&gt;
68 &lt;echo&gt;In &amp;lt;catch&amp;gt;.&lt;/echo&gt;
69 &lt;/catch&gt;
70
71 &lt;finally&gt;
72 &lt;echo&gt;In &amp;lt;finally&amp;gt;.&lt;/echo&gt;
73 &lt;/finally&gt;
74 &lt;/trycatch&gt;
75
76 &lt;echo&gt;As property: ${foo}&lt;/echo&gt;
77 &lt;property name=&quot;baz&quot; refid=&quot;bar&quot; /&gt;
78 &lt;echo&gt;From reference: ${baz}&lt;/echo&gt;
79 </pre>
80
81 <p>results in</p>
82
83 <pre>
84 [trycatch] Caught exception: Tada!
85 [echo] In &lt;catch&gt;.
86 [echo] In &lt;finally&gt;.
87 [echo] As property: Tada!
88 [echo] From reference: Tada!
89 </pre>
90
91 <hr>
92 <p align="center">Copyright &copy; 2002-2003 Ant-Contrib Project. All
93 rights Reserved.</p>
94
95 </body>
96 </html>