Originally posted by Arjun Reddy:
So, why use the try catch block then?
It just so happens that both methods of handling the Exception seem to use printStackTrace().
Without the try-catch, the Exception propagates until it reaches the JVM, and the JVM does two things (at least):
It prints the stack trace, andIt terminates the thread with the Exception in.If you only have one thread, then the JVM terminates as well.
With the try-catch, assuming you catch the right sort of Exception, the thread continues to run to completion.
Lots more about it in
the Java Tutorials.