JavaE is initialized like JavaO the execution is assumed to start normally.
JavaE provides new statements and handling of run-time exceptions, which may occur during expression evaluation. Therefore the machine execJavaE consists of two submachines, to be de_ned below, consisting of additional rules for the new statements and for the handling of some characteristic expression evaluation exceptions.
The execution of throw, try, finally statements is started by the submachine execJavaStmE, de_ned in Fig. below, by passing the control to the evaluation of the related exception expression or to the execution of the _rst direct substatement. When the exception value ref of a throw statement has been computed, and if it turns out to be null , a NullPointerException is reported to the enclosing phrase using failUp, which allocates a new object for the exception and throws the exception (whereby the execution of the corresponding finally code starts, if there is some, together with the search for the appropriate exception handler). When appropriate we use fail instead of failUp to substitute the current phrase by the corresponding exception.
If the exception value ref of a throw statement is not null , the abruption Exc(ref ) is passed up to the (position of the) throw statement, thereby abrupting the control ow with the computed exception as reason [18, x14.16].
Upon normal completion of a try statement, the machine passes the control to the parent statement, whereas upon abrupted completion the machine attempts to catch the exception by one of the catch clauses. The catching condition is the compatibility of the class of the exception with one of the catcher classes. If the catching fails, the exception is passed to the parent statement, as is every other abruption which was propagated up from within the try statement; otherwise the control is passed to the execution of the relevant catch statement. Upon normal completion of this statement, the machine passes the normal control up, whereas upon abrupted completion the new exception is passed up to the parent statement.
For a finally statement, upon normal or abrupted completion of the _rst direct substatement, the control is passed to the execution of the second direct substatement, the finally statement proper. Upon normal completion of this statement, the control is passed up, together with the possible reason of abruption, the one which was present when the execution of finally statement proper was started, and which in this case has to be resumed after execution of the finally statement proper. However, should the execution of this finally statement proper abrupt, then this new abruption is passed to the parent statement.
Exceptions are passed up when they have been propagated to the position directly following a label.
There is a special case which has to be added, namely uncaught exceptions in class initializers. For them Java speci_es the following strategy. If,
Execution of JavaE statements
During execution of the body of a static initializer, an exception is thrown, and if this is not an Error or one of its subclasses, throw ExceptionIn- InitializerError. If the exception is compatible with Error, then the exception is rethrown in the directly preceding method on the frames stack.
If the attempt to catch a thrown exception in the current method fails, i.e., when pos reaches _rstPos, the exception is passed to the invoker of this method (if there is some), to continue the search for an exception handler there. If the current method is a class initializer, then the corresponding class becomes unusable.
A throw statement can be user-de_ned, whereby an exception is thrown explicitly. A throw statement can also be due to the occurrence of run-time exceptions which are thrown, if certain semantic constraints for binary op92
Execution of JavaE expressions
erations, target expressions and reference type cast expressions do not hold.
The submachine execJavaExpE in Fig.below de_nes the semantics of three characteristic run-time exceptions which can occur. A binary expression throws an ArithmeticException, if the operator is an integer division or remainder operator and the right operand is 0 [18, x15.13, 15.14]. An instance target expression throws a NullPointerException, if the operand is null . A reference type cast expression throws a ClassCastException, if the value of the direct subexpression is neither null nor compatible with the required type [18, x15.15].
If the current class is in an erroneous state, then initialization is not possible and a NoClassDefFoundError is thrown. This is expressed by the following
In JavaE the de_nition of propagation of abruptions is re_ned for jump and return instructions, to the e_ect that try statements suspend these abruptions for execution of relevant finally code. As explained above, after the execution of this finally code, that abruption will be resumed (unless during the finally code a new abruption did occur which cancels the original one).
Example (; CD). The following program shows that, if a return expression is included in a try block, then the finally block is executed before the expression isreturned.
Since the finally block contains another return expression, the value of i * i is returned and the value i + i is discarded.
JVM Related Interview Questions
|Java Script Interview Questions||Adv Java Interview Questions|
|Core Java Interview Questions||AJAX Interview Questions|
|Android Interview Questions||Java applet Interview Questions|
|Java 8 Interview Questions||JBOSS Interview Questions|
|Advanced jQuery Interview Questions||Apache Tomcat Interview Questions|
|Application Virtualization Interview Questions||Java 9 Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.