• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error Handling in ANT

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to detect an error and write error and success log into the log files. I am new to ANT and having a big problem finding the right approach.
Please help. I have tried <FAIL>,etc and so far ..... no good.

thank you very much.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure from your explanation what you are trying to do.

Below are some examples using fail task from ant manual:

[ February 20, 2005: Message edited by: Carol Enderlin ]
 
Anatoly Bondar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's correct. HOwever, when I use <fail/> right after <sql> even if it is fine, it is failing. Seems like it goes there anyway. I am just trying to check, if something failed, wright into fail log, otherwize - success log.

hank you for any help.
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, if you put <fail/> in your build you are telling it to fail. There is some if/unless logic you can put in fail task but that only helps with the fail case, and unless you are having things not fail on errors I guess it wouldn't reach that.

What are you trying to accomplish with your success and fail logs? Unless you specify otherwise many (most?) tasks will halt the build when they fail. And some information is output about why it failed.

You need some confirmation that something succeeded and you aren't getting that? I'm not sure how to help when I don't understand what you are trying to accomplish.

You mentioned the sql task. It has an attribute "onerror" = Action to perform when statement fails: continue, stop, abort. Required = No, default "abort". I tried it out real quick. With the default setting I got this:

mySql:

BUILD FAILED
C:\_Work\java\build\build.xml:12: Class Not Found: JDBC driver org.database.jdbcDriver could not be loaded
 
Anatoly Bondar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All I am trying to accomplish is, when SQL for some reason failes(user_id or passowrd, etc.) programm will write the record in the log file.

Thanx
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What log file and why isn't it writing it?
 
Anatoly Bondar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a regular txt file. It does writes, but if I do <fail> it writes always there. I am trying to catch the condition right after <SQL> get executed. I just need to write something like "Succes" or "Failed", but seems like I cann't catch it . Right after SQl it failes and kiks it out. I have triet to set some var. , etc.
 
Anatoly Bondar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something like <try> and <catch> would be perfect.
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you looked at the Listeners & Loggerssection of the Ant Manual. You might find something useful in there such as the Log4jListener.


Log4jListener
Passes build events to Log4j, using the full classname's of the generator of each build event as the category:

build started / build finished - org.apache.tools.ant.Project
target started / target finished - org.apache.tools.ant.Target
task started / task finished - the fully qualified classname of the task
message logged - the classname of one of the above, so if a task logs a message, its classname is the category used, and so on.
All start events are logged as INFO. Finish events are either logged as INFO or ERROR depending on whether the build failed during that stage. Message events are logged according to their Ant logging level, mapping directly to a corresponding Log4j level.

ant -listener org.apache.tools.ant.listener.Log4jListener

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic