Point of throwing different exception [closed]

Yes and no. The point of having two different catch blocks is so that the program can handle different errors in different ways. Further, by splitting the code into two blocks, the original code maintains the original exception type to be caught by a different method. In this case, however, since they are both doing the same thing (rethrowing the exception) you could combine into a single catch(Exception e) but this is not recommended. You should always be as specific as possible when catch exceptions. Since the Exception class is the parent of all exceptions, including FileNotFoundException, it is almost always bad practice to catch Exception alone.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top