Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
scroll top