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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Ant-contrib Tasks: Trycatch</title>
</head>
<body>
<h1>Trycatch</h1>
<p>A wrapper that lets you run a set of tasks and optionally run a
different set of tasks if the first set fails and yet another set
after the first one has finished.</p>
<p>This mirrors Java's try/catch/finally.</p>
<p>The tasks inside of the required <code><try></code>
element will be run. If one of them should throw a BuildException
several things can happen:</p>
<ul>
<li>If there is no <code><catch></code> block, the
exception will be passed through to Ant.</li>
<li>If the property attribute has been set, a property of the
given name will be set to the message of the exception.</li>
<li>If the reference attribute has been set, a reference of the
given id will be created and point to the exception object.</li>
<li>If there is a <code><catch></code> block, the tasks
nested into it will be run.</li>
</ul>
<p>If a <code><finally></code> block is present, the task
nested into it will be run, no matter whether the first tasks have
thrown an exception or not.</p>
<h2>Parameters</h2>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Required</th>
</tr>
<tr>
<td valign="top">property</td>
<td valign="top">Name of a property that will receive the
message of the exception that has been caught (if any)</td>
<td align="center" valign="top">No.</td>
</tr>
<tr>
<td valign="top">reference</td>
<td valign="top">Id of a reference that will point to the
exception object that has been caught (if any)</td>
<td align="center" valign="top">No</td>
</tr>
</table>
<h2>Example</h2>
<pre>
<trycatch property="foo" reference="bar">
<try>
<fail>Tada!</fail>
</try>
<catch>
<echo>In &lt;catch&gt;.</echo>
</catch>
<finally>
<echo>In &lt;finally&gt;.</echo>
</finally>
</trycatch>
<echo>As property: ${foo}</echo>
<property name="baz" refid="bar" />
<echo>From reference: ${baz}</echo>
</pre>
<p>results in</p>
<pre>
[trycatch] Caught exception: Tada!
[echo] In <catch>.
[echo] In <finally>.
[echo] As property: Tada!
[echo] From reference: Tada!
</pre>
<hr>
<p align="center">Copyright © 2002-2003 Ant-Contrib Project. All
rights Reserved.</p>
</body>
</html>
|