File: trycatch.html

package info (click to toggle)
ant-contrib 1.0~b3%2Bsvn177-10
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,036 kB
  • sloc: java: 12,697; xml: 2,675; makefile: 7
file content (96 lines) | stat: -rw-r--r-- 2,812 bytes parent folder | download | duplicates (6)
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>&lt;try&gt;</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>&lt;catch&gt;</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>&lt;catch&gt;</code> block, the tasks
      nested into it will be run.</li>
    </ul>

    <p>If a <code>&lt;finally&gt;</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>
&lt;trycatch property=&quot;foo&quot; reference=&quot;bar&quot;&gt;
  &lt;try&gt;
    &lt;fail&gt;Tada!&lt;/fail&gt;
  &lt;/try&gt;

  &lt;catch&gt;
    &lt;echo&gt;In &amp;lt;catch&amp;gt;.&lt;/echo&gt;
  &lt;/catch&gt;

  &lt;finally&gt;
    &lt;echo&gt;In &amp;lt;finally&amp;gt;.&lt;/echo&gt;
  &lt;/finally&gt;
&lt;/trycatch&gt;

&lt;echo&gt;As property: ${foo}&lt;/echo&gt;
&lt;property name=&quot;baz&quot; refid=&quot;bar&quot; /&gt;
&lt;echo&gt;From reference: ${baz}&lt;/echo&gt;
</pre>

    <p>results in</p>

<pre>
  [trycatch] Caught exception: Tada!
      [echo] In &lt;catch&gt;.
      [echo] In &lt;finally&gt;.
      [echo] As property: Tada!
      [echo] From reference: Tada!
</pre>

    <hr>
    <p align="center">Copyright &copy; 2002-2003 Ant-Contrib Project. All
    rights Reserved.</p>

  </body>
</html>