db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kathey Marsden <kmarsdende...@sbcglobal.net>
Subject Re: [jira] Commented: (DERBY-214) Remove System.exit() calls from the DB2jServerImpl.java
Date Thu, 28 Apr 2005 13:46:15 GMT
David Van Couvering wrote:

> We could add an argument that indicates whether or not the main
> program should call System.exit() or just return.  It's very valuable
> to have a non-zero exit status when calling a command from the
> command-line, for better scriptability...
>
> e.g. "-noSysExit"
>
> But I think what would be better is if applications like Eclipse don't
> call main() but call the execute() method, which only throws an
> exception.   This same issue exists for all the Derby tools, and it
> would be good if we had a policy that didn't require a "-noSysExit"
> option on every command.
>
> I can add an execute() method to NetworkServerControl so it's on the
> same class as the main() method.

What do you think about main throwing an exception?  If we can do that
then it might  avoid changing the public API or doc.
I don't know if that is a commonly accepted practice or not. I tried this.

public static void main(String[] args) throws Exception
    {
        conntype = null;
        if (args.length < 1 || args[0].equals("throw"))
            throw new Exception ("main throws exception");
        else if (args[0].equals("exit0"))
                 System.exit(0);
        else if (args[0].equals("exit1"))
            System.exit(1);
        else if (args[0].equals("return"))
            return;
    }
$ java MainException throw
Exception in thread "main" java.lang.Exception: main throws exception
        at MainException.main(MainException.java:20)
$ echo $?
1
$ java MainException return
$ echo $?
0
$ java MainException exit1
$ echo $?
1
$ java MainException exit0
$ echo $?
0




Mime
View raw message