Web server setup - 818 Exception Handling Chapter 14 of method quotientin

818 Exception Handling Chapter 14 of method quotientin the try block (line 65). Line 66 displays the result of the calculation in the third JTextField. In this case, the try block completes successfully, so the program skips the catch blocks and the actionPerformed method completes execution normally. Note that when quotient throws the DivideByZeroException, quotient s block expires (i.e., the method terminates). This would cause any of its local variables to be destroyed objects that were referenced by local variables in the block would have their reference counts decremented accordingly (and are possibly marked for garbage collection). Also, the try block from which the method was called expires before line 66 can execute. Here, too, if there were local variables created in the tryblock prior to the exception being thrown, these variables would be destroyed. If a NumberFormatExceptionis generated by lines 62 63, the try block expires and execution continues with the exception handler at line 70, which displays an error message to tell the user to input integers. Then the actionPerformedmethod continues with the next valid statement after the catch blocks (i.e., the method terminates in this example). 14.9 Rethrowing an Exception It is possible that the catchhandler that catches an exception may decide it cannot process the exception, or it may want to let some other catch handler handle the exception. In this case, the handler that received the exception can rethrow the exception with the statement throw exceptionReference; where exceptionReference is the parameter name for the exception in the catch handler. Such a throw rethrows the exception to the next enclosing try block. Even if a handler can process an exception, and regardless of whether it does any processing on that exception, the handler still can rethrow the exception for further processing outside the handler. A rethrown exception is detected by the next enclosing try block and is handled by an exception handler listed after that enclosing try block. 14.10 throws Clause A throws clause lists the exceptions that can be thrown by a method as in int functionName( parameterList ) throws ExceptionType1, ExceptionType2, ExceptionType3, { // method body } The types of exceptions that are thrown by a method are specified in the method definition with a comma-separated list in the throws clause. A method can throw objects of the indicated classes, or it can throw objects of their subclasses. Some exceptions can occur at any point during the execution of the program. Many of these exceptions can be avoided by coding properly. These are run-time exceptions, and they derive from class RuntimeException. For example, if your program attempts to access an out-of-range array subscript, an exception of type ArrayIndexOutOf- BoundsException (derived from RuntimeException) occurs. Your program clearly can avoid such a problem; hence, it is a run-time exception.
We recommend high quality webhost to host and run your jsp application: christian web host services.

Leave a Reply