ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Walend <dwal...@eecs.tufts.edu>
Subject System.exit() [was Re: Executing java via ExecuteJava raising an IllegalAccessError?]
Date Sat, 09 Sep 2000 21:06:56 GMT
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



Mime
View raw message