You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by David Walend <dw...@eecs.tufts.edu> on 2000/09/09 23:06:56 UTC

System.exit() [was Re: Executing java via ExecuteJava raising an IllegalAccessError?]

I'll pick this up, but don't want to start a religious war. What follows
is high-level foofy design stuff, and there really are some situations
when you want to call System.exit(). 

On Sat, 9 Sep 2000, David Medinets wrote:

> Hi. Why is using System.exit() foolish? 

If the code containing System.exit() is always stand-alone, it's not
foolish. If someone tries to call that code from inside their own, then
the System.exit() can end the java process too soon.

For example, weblogic's ejbc calls System.exit(). (Or at least it used
to.) That works fine, as long as I called ejbc by hand. When I tried to
write some code to use ejbc and then do something else, the code didn't
work; ejbc exited and my own code never ran.

> What should be used instead? 

If nothing is wrong, then return; is a good option. (I've seen some
complex code that returns an int indicating {done|not done}.
System.exit() does this for the shell.)

If something is horribly wrong, throw a subclass of RuntimeException that
says what's going on as clearly as possible.

> Are you
> referring to thinging like handling unrecoverable exceptions that should be
> thrown up the chain or to exceptions like files not being found that could
> be handled directly?

Both I suppose. I've discovered that code I've never expected anyone to  
use leaks out from my hard drive as library code. Avoiding System.exit()
saves me lots of support work and refactoring.

Hope that helps. If it pisses someone off, sorry.

Dave



Re: System.exit() [was Re: Executing java via ExecuteJava raising an IllegalAccessError?]

Posted by David Medinets <me...@mtolive.com>.
thanks for confirming my understanding. I plan to create some Ant tasks that
can analyze ColdFusion templates and generate documentation (like javadoc
does for java). And I'd like to learn some organization techniques and
coding techniques from the Ant project.

----- Original Message -----
From: "David Walend" <dw...@eecs.tufts.edu>


> I'll pick this up, but don't want to start a religious war. What follows
> is high-level foofy design stuff, and there really are some situations
> when you want to call System.exit().