ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 9414] New: - Don't catch Throwable after System.exit(0)
Date Sat, 25 May 2002 12:02:11 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9414>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9414

Don't catch Throwable after System.exit(0)

           Summary: Don't catch Throwable after System.exit(0)
           Product: Ant
           Version: 1.5Beta1
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: Minor
          Priority: Other
         Component: Core
        AssignedTo: ant-dev@jakarta.apache.org
        ReportedBy: clemens@kclee.com


Hi,

I think the behavior of ant when exiting is undesirable.

After ant has done its job successful it does a normal
System.exit(0). Unfortunately there is a try/catch around it.

org/apache/tools/ant/Main.java:start(..){
...
        try {
            m.runBuild(coreLoader);
            System.exit(0);
        } catch (BuildException be) {
            if (m.err != System.err) {
                printMessage(be);
            }
            System.exit(1);
        } catch (Throwable exc) {
            exc.printStackTrace();
            printMessage(exc);
            System.exit(1);
        } finally {
...
}

I don't mind catching the BuildException around the runBuild(..),
but trapping the System.exit(0) is not so good, IMHO.

Here is why.

I invoke ant from an external program (a Java shell, CleSh) and of
course have to prevent the exit using a security manager which 
throws a SecurityException when ant tries to exit. Now instead of
letting the external program handle the security exception, ant gets
in the way and prints that silly stack trace which the jvm would by
default print anyway if ant would have been started on its own.

So please don't catch the Throwable, or re-throw a catched 
SecurityException, or do the System.exit(0) outside the try block
afterwards.

Maybe I have overlooked a good reason why to catch everything.


Btw, here is how I help myself for now. But it is a damn ugly workaround.

The security manager throws a special security exception which has
printStackTrace() overwritten and which throws another exception when
invoked. That way I get no stack trace and the second exception does not
get catched by ant. Of course this might have nasty side effects for other
applications.

Thanks very much,
   Clemens

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message