| Author |
Doubt in Exception Handling
|
ayush raj
Ranch Hand
Joined: Jan 15, 2012
Posts: 60
|
|
What should be the output ?
I thought it to be Runtime exception since a number is divided by zero . But actually compilation fails !! How?
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3795
|
|
|
And compilation fails with what error message?
|
 |
ayush raj
Ranch Hand
Joined: Jan 15, 2012
Posts: 60
|
|
the error message is :
exception java.lang.InterruptedException is never thrown in body of corresponding try statement
Is it that that what ever exception is thrown inside a try block , the first catch has to be the corresponding class exception handler ??
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3795
|
|
|
That's the problem. InterruptedException is a checked exception. The compiler therefore knows that it cannot possibly be thrown from the try block, so it knows that trying to catch it is an error. Runtime exceptions don't have the same effect (even though in this case theoretically the compiler could work out that ArrayIndexOutOfBoundsException can't be thrown).
|
 |
 |
|
|
subject: Doubt in Exception Handling
|
|
|