Reputation: 27375
In the JLS 11 says:
During the process of throwing an exception, the Java Virtual Machine abruptly completes, one by one, any expressions, statements, method and constructor invocations, initializers, and field initialization expressions that have begun but not completed execution in the current thread.
Suppose I hvae the following code:
public static void m(){
throw new SQLException();
}
public static void d(){
m();
}
public static void main(String[] args){
d();
}
In the case we have m()
completes abruptly because of throwing SQLException
. JLS doesn't say explcitly that the Java Virtual Machine abruptly completes, one by one, any expressions, statements, method etc for the same reason. That's it can mean d()
completes for a different reason from throwing SQLException
. Could you clarify that moment?
Upvotes: 2
Views: 78
Reputation: 718758
JLS doesn't say explcitly that the Java Virtual Machine abruptly completes, one by one, any expressions, statements, method etc for the same reason.
It doesn't says this in Section 11, but the termination reasons are discussed in other parts of the spec; e.g JLS 14.1 and JLS 15.6.
As @biziclop notes, there is text in 14.1 that specifically states that termination reasons don't change as an exception propagates. (They can however change when an exception is handled ...)
But this should not be news to you. It is consistent with the way that the Java tutorial and text books say that Java exceptions behave.
Upvotes: 2
Reputation: 49724
It isn't defined there, but it is in Chapter 14, which talks about abrupt completion in general:
If a statement evaluates an expression, abrupt completion of the expression always causes the immediate abrupt completion of the statement, with the same reason. All succeeding steps in the normal mode of execution are not performed.
Unless otherwise specified in this chapter, abrupt completion of a substatement causes the immediate abrupt completion of the statement itself, with the same reason, and all succeeding steps in the normal mode of execution of the statement are not performed.
So we can conclude it isn't specified for exceptions because it's true for all possible reasons of abrupt completion, not just exceptions.
Upvotes: 2