What are benefits of requiring the exceptions


Discuss teh below:

Task:

You will have noticed in the reading about throwing exceptions, that some exceptions (such as java.io.IOException) must be caught by your code whenever you do something that may throw them, otherwise the Java compiler complains. Any method you write that can throw such an exception must be declared as throws ExceptionName. This is the way it works for most exceptions: you must declare that you can throw them, and you must handle them if they can be thrown.

Q1: Why would Java require this? What are some benefits of requiring that exceptions be either explicitly handled or rethrown?

Q2: Why is there this special case for some exceptions? What is different about something like ArrayIndexOutOfBoundsException that makes it beneficial to not have to enclose every statement that could produce it with a try/catch?

Solution Preview :

Prepared by a verified Expert
JAVA Programming: What are benefits of requiring the exceptions
Reference No:- TGS01934903

Now Priced at $25 (50% Discount)

Recommended (91%)

Rated (4.3/5)