In the following code:
void foo() throws InterruptedException {
try {
f1();
}
catch (InterruptedException e) {
f2();
throw e;
}
finally {
f3(); //breakpoint hit twice
}
}
When InterruptedException is thrown by f1(), the breakpoint in the finally block is hit twice, but f3() is entered only once while debugging. I'm wondering if this is normal.
If you throw an exception in a method by stating it throws the exception, then you do not handle it inside the method.
Actually the code you shared has lots of mistakes that I can't show my example, so I'll show my example.
Lets say you have a method called foo() that throws an exception
Now, if you want to use
foo()method in afoo2()method, then you either declare thefoo2()as throws ExceptionDivisionByZeroor you should handle it inside thefoo2()method. DO NOT DO BOTHLike this:
or this:
output of this last foo2() code is either
No Exception.
I'm done.
or
Caught.
I'm done.
0 //because int type initialized to zero.