You can write a single catch block to handle all the exceptions thrown during the program execution as follows : If you use the Superclass Exception in the catch block then you will not get the valuable information about each of the exception thrown during the execution, though you can find out the class of the exception occurred. Also it will reduce the readability of the code as the programmer will not understand what is the exact reason for putting the try-catch block.
try {
// code that can throw exception of any possible type}catch (Exception e) {
e.printStackTrace();}
No comments:
Post a Comment