Consider the following code:
int dummy() {
int x = 0;
try {
x = x + 1;
throw new Exception();
} catch (Exception e) {
x = x + 2;
return x;
} finally {
x = x + 4;
}
I need to "predict" the behaviour of this method without programming it. My question is, what will the return value be?
My guess would be that when an exception occurs, the finally
block will be realized, so the value of x
will be 4. But I think the value will not be returned. And if no exception occurs, the value will be 2 and it will be returned.
I'm a complete beginner (less than 3 months) in programming so I might be missing something.