/usr/share/doc/libantelope-java/manual/bk03ch07.html is in libantelope-java-doc 3.5.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 97 98 99 100 101 102 103 104 105 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 7. Try Task</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Antelope Users Guide"><link rel="up" href="bk03.html" title="Additional Ant Tasks"><link rel="prev" href="bk03ch06.html" title="Chapter 6. SwitchTask"><link rel="next" href="bk03ch08.html" title="Chapter 8. Unset Task"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 7. Try Task</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk03ch06.html">Prev</a> </td><th width="60%" align="center">Additional Ant Tasks</th><td width="20%" align="right"> <a accesskey="n" href="bk03ch08.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="TryTask"></a>Chapter 7. Try Task</h1></div></div></div>
@style@
<p>
The "Try" task works similarly to the try/catch/finally construct in Java. This task is useful when a particular task might fail, but the build should not fail if it does. An example is the "mail" task will fail if the mail server is not available, but the build should not fail if the mail message cannot be delivered.
</p><p>
To use this task in your build files, include a task definition like this:
</p><p>
</p><pre class="programlisting">
<taskdef name="try" classname="ise.antelope.tasks.TryTask"/>
</pre><p>
</p><p>
A quick example is probably all that is necessary:
</p><pre class="programlisting">
<tempfile property="temp.file" destdir="${java.io.tmpdir}"
prefix="delete" suffix=".tmp"/>
<try>
<!-- use 'get' task to post to the unit test status servlet. It
would be better to use a post for this, but this shows a good
use of 'finally'. -->
<get
src="http://mycompany.com/servlet/junit?testnum=${test.num}&status="${status}"
dest="${temp.file}"/>
<catch>
<echo>Unit test servlet update failed.</echo>
</catch>
<finally>
<delete file="${temp.file}"/>
</finally>
</try>
</pre><p>
</p><p>
Unlike the Java "try", neither the "catch" block nor the "finally" block are required. Also, the order does not matter, the "catch" block may be listed first, followed by the "finally", followed by the tasks that may fail.
</p><p>
</p><div class="table"><a name="idp62271472"></a><p class="title"><b>Table 7.1. Try Task Attributes</b></p><div class="table-contents"><table summary="Try Task Attributes" border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>break</td><td>If true and a nested task fails, no other nested tasks will execute. If false, all nested tasks will execute regardless of whether a previous task failed. Note that for each failed task, the 'catch' block (if defined) will execute.</td><td>true</td><td>No</td></tr><tr><td>printstacktrace</td><td>If true, the exception stack trace from a failed task will be logged. </td><td>false</td><td>No</td></tr><tr><td>stacktraceproperty</td><td>Specify a property to store the stack trace of any exception. </td><td>None</td><td>No</td></tr><tr><td>printmessage</td><td>If true, the exception message from a failed task will be logged. If printstacktrace is set to true, this attribute is ignored as the exception message is printed as part of the stack trace.</td><td>true</td><td>No</td></tr><tr><td>messageproperty</td><td>Specify a property to store the message line of any exception.</td><td>None</td><td>No</td></tr></tbody></table></div></div><p><br class="table-break">
</p><p>
The next example shows the "break" attribute set to "no". In this case, the second echo task will execute.
</p><p>
</p><pre class="programlisting">
<target name="test" description="This exercises the Try task.">
<try break="no">
<echo>I am trying...</echo>
<fail message=" and I failed..."/>
<echo> but I did not die!</echo> <!-- this WILL print -->
</try>
</target>
</pre><p>
</p><p>
This slightly more practical example uses the <a class="link" href="bk03ch09.html" title="Chapter 9. Variable Task">Variable</a> task coupled with "try" to run a series of tests. All tests will run even if a preceding test fails. The "catch" block logs a message of each failed test.
</p><p>
</p><pre class="programlisting">
<target name="runTests" messageproperty="msg">
<try catch="testFailed" break="no">
<var name="testname" value="fileUtilTests"/>
<antcall target="runFileUtilTests"/>
<var name="testname" value="imageUtilTests"/>
<antcall target="runImageUtilTests"/>
<var name="testname" value="imageConversionTests"/>
<antcall target="runImageConversionTests"/>
<catch>
<!-- log a test failure -->
<echo file="test.log" append="yes">
Test suite ${testname} failed: ${msg}
</echo>
</catch>
</try>
</target>
</target>
</pre><p>
</p><p>
The following example uses a nested Finally to clean up resources:
</p><pre class="programlisting">
<tempfile property="temp.file" destdir="${java.io.tmpdir}"
prefix="delete" suffix=".tmp"/>
<try>
<!-- use 'get' task to post to the unit test status servlet. It
would be better use use a post for this, but this shows a good
use of 'finally'. -->
<get
src="http://mycompany.com/servlet/junit?testnum=${test.num}&status="${status}"
dest="${temp.file}"/>
<catch>
<echo>Unit test servlet update failed.</echo>
</catch>
<finally>
<delete file="${temp.file}"/>
</finally>
</try>
</pre><p>
See the <a class="link" href="bk03ch17.html" title="Chapter 17. HTTP Post">post</a> task for a better way to do a post.
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk03ch06.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="bk03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk03ch08.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 6. SwitchTask </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 8. Unset Task</td></tr></table></div></body></html>
|