I have a program that has to initialize a few big things (connect to a few databases, parse some XML) and without the initialization being successful the program would not be able to continue.Right now I have my main method throwing just a general Exceptionpublic static void main(String[] args) throws Exception{    //Throws numerous types of Exceptions    WhateverObject we = WhateverObject.getInstance();    we.doSomething();}My question is, is there a better way to handle this? Should I catch the exception and then print out that it failed an exit? Something else maybe? Note, there's no hope of program recovery at this point.
Proper action when a Java program fails
java;exception handling
For many (small) applications, what you are doing is OK. Not great, but OK.The problems come with the following:exception traces will be printed to STDERR (the console, not a file). If the console output is discarded, the error is lost (eg. .... >& /dev/null)the exit code of the application may or may not be set to an error codeif one of your sub-systems succeeds before another one fails, and it starts a non-daemon thread, then your application may not even terminate at all.For any robust application I recommend using an uncaught-exception handler. This handler should log the uncaught exception to a logical place, and it should System.exit(1) (or some other exit code).This may complicate things with threads that do not trap their exceptions, but that is bad pracitce as well....See the documentation for the uncaught exception handler, and some tutorials.