| 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><try></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><catch></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><catch></code> block, the tasks |
| 31 | nested into it will be run.</li> |
| 32 | </ul> |
| 33 | |
| 34 | <p>If a <code><finally></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 | <trycatch property="foo" reference="bar"> |
| 63 | <try> |
| 64 | <fail>Tada!</fail> |
| 65 | </try> |
| 66 | |
| 67 | <catch> |
| 68 | <echo>In &lt;catch&gt;.</echo> |
| 69 | </catch> |
| 70 | |
| 71 | <finally> |
| 72 | <echo>In &lt;finally&gt;.</echo> |
| 73 | </finally> |
| 74 | </trycatch> |
| 75 | |
| 76 | <echo>As property: ${foo}</echo> |
| 77 | <property name="baz" refid="bar" /> |
| 78 | <echo>From reference: ${baz}</echo> |
| 79 | </pre> |
| 80 | |
| 81 | <p>results in</p> |
| 82 | |
| 83 | <pre> |
| 84 | [trycatch] Caught exception: Tada! |
| 85 | [echo] In <catch>. |
| 86 | [echo] In <finally>. |
| 87 | [echo] As property: Tada! |
| 88 | [echo] From reference: Tada! |
| 89 | </pre> |
| 90 | |
| 91 | <hr> |
| 92 | <p align="center">Copyright © 2002-2003 Ant-Contrib Project. All |
| 93 | rights Reserved.</p> |
| 94 | |
| 95 | </body> |
| 96 | </html> |