Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ant to not print the BuildException/ExitStatusException stack trace

Tags:

java

ant

I have written an ant task (bnd) that needs to indicate failure. The only way to indicate failure that I found is to throw a BuildException/ExitStatusException. However, I do not want a stack trace because it just takes up unnecessary screen space. Any idea how to achieve this?

like image 443
Peter Kriens Avatar asked Sep 13 '10 13:09

Peter Kriens


People also ask

What causes a stack trace error?

Whenever a certain function call throws an error, you'll have a collection of function calls that lead up to the call that caused the particular problem. This is due to the LIFO behavior of the collection that keeps track of underlying, previous function calls. This also implies that a stack trace is printed top-down.

How do I print a stack trace for exceptions?

Using printStackTrace() method − It print the name of the exception, description and complete stack trace including the line where exception occurred. Using toString() method − It prints the name and description of the exception. Using getMessage() method − Mostly used. It prints the description of the exception.

Should stack traces be logged?

Logging the stack traces of runtime exceptions assists developers in diagnosing runtime failures. However, unnecessary logging of exception stack traces can have many negative impacts such as polluting log files.


1 Answers

Check out the tutorial at http://ant.apache.org/manual/tutorial-writing-tasks.html#complex

There they show an example that just fails gracefully, throwing a BuildException in the custom task but not showing the stack trace in the console window.

The code to pay attention to is in the execute() method of the 'HelloWorld' Class, and where the helloworld task is called from the use.fail target.

like image 159
bakoyaro Avatar answered Sep 18 '22 00:09

bakoyaro