Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Any time a Perl, Python, C++ or Tcl program halts with an unhandled exception, those language runtimes take care to register a non-zero exit code for the process. Even Eclipse-based programs return 1 if they fail during startup. Programs run by the standard java.exe, however, happily return zero no matter how abruptly they end, unless the program calls System.exit() with an exit value. Even AssertionFailedError or UnsatisfiedLinkError are reported back to the calling program as successful exits.

Of course not all systems have program return codes, but Unix and Windows were important enough to warrant java.lang.Process.exitValue() for child processes; don't they also warrant honouring conventions for parent processes?

Is this a flaw in the language design or just in the implementation? Is there an argument that it's a good idea?

share|improve this question
    
Wonder if this is not better suited on StackOverflow... Just an opinion, though. –  gablin Nov 22 '10 at 12:28
    
@gablin Mmm, indeed I started writing this question on SO then changed my mind and posted it here. –  James Nov 22 '10 at 19:16
add comment

1 Answer

up vote 14 down vote accepted

If the Java Language Specification does not explicitly define what exit value to expect, then it is undefined and you should not rely on it.

You need to catch Throwable in your main method, and call System.exit(1) yourself.

share|improve this answer
4  
So isn't it a shortcoming to leave it undefined? –  James Nov 22 '10 at 19:11
3  
Maybe, maybe not. The only important thing is what the JLS says. –  user1249 Nov 22 '10 at 19:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.