ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: Error Handling
Date Wed, 19 May 2004 19:52:35 GMT
Hi Doug/All,

This helped me lot. I coded my job exactly similar way and is working 

I have one more problem, i.e in my requirement I have to send an email 
with the console log message to everyone saying that build is where 
successful or failed. 

So as per the below email pls. map my targets as follows:

normalTarget    = build_dev
failTarget            = sendFailEmail
successTarget = sendSuccessEmail

In "build_dev" target I am generating log file and I am attaching that 
file in the "send*Email" targets. So,if the build is success it is 
attaching the full log file fine, but when build is failed it is able 
attach the log file only with the content before it got failed, that means 
it is not captuing [trycatch] block error message in the log file. How 
could we solve this problem? My major requirement to send the mail is to 
see the error message where does it failed/what is the problem.

Pls. advice if there is any better way to handle this problem... I would 
appreciate your earliest response.


"Daniels, Doug" <>
05/19/2004 10:01 AM

        To:     Thirumala Thoka/Corporate/FSC@Fairchild,
        Subject:        RE: Error Handling

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 

    <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, 

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.


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message