ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniels, Doug" <>
Subject RE: Error Handling
Date Wed, 19 May 2004 14:01:03 GMT
You can use the ant-contrib ( <trycatch> task (,
"Trytask is 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."

For example:

<target name="taskFailCheck">
<trycatch property="taskFailed" reference="errorRef">
    <antcall target="normalTarget" />

    <echo>Error caught: ${errorRef}</echo>

    <echo>Check if we failed and perform task otherwise perform other task.</echo>

    <if> <isset property="taskFailed" /> <then>
       <antcall target="failTarget" />


<!-- otherwise perform succesful task -->

       <antcall target="successTarget" />



You just replace the normalTarget, failTarget, and successTarget with your targets, you could
also just check the taskFailed property in the other targets themselves, for example:

<target name="successTarget" unless="taskFailed">


<target name="failedTarget" if="taskFailed">

then you'd have a target setup like this to setup the order:

<target name="masterTarget" depends="taskFailCheck, successTarget, failedTarget"/>

This task would run your trycatch then it would run either the successTarget or the failedTarget
depending on the success and failure of the normalTarget target.

To use ant-contrib tasks. First Download the ant-contrib tasks jar and then at the top of
your build file you must declare the ant-contrib tasks:
<taskdef resource="net/sf/antcontrib/">
    <pathelement location="/usr/share/java/lib/ant-contrib-0.3.jar"/>

-----Original Message-----
Sent: Monday, May 17, 2004 4:58 PM
Subject: Error Handling

Hi All,

How do we capture the error on ANT target, if it does success do one thing 
otherwise do other thing. So, basically how do we code this requirement.

I did little bit of try with "failureonerror", "haltonerror" attributes 
but it's not accepting those attributes at all.
I would appreciate your ealiest response. Pls. do ask me if you need more 
details about the question.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message