Exception Handling (Lecture 9.1)
Exception Handling (Lecture 9.1)
Enclose the code inside a try block that you want to monitor or which can
possibly activate an exception.
Include a catch clause right after the try block. The catch clause specifies
the exception type that you wish to catch.
Once an exception is thrown, program control transfers from the try block into the catch
block.
catch (ArithmeticException e) {
System.out.println("Exception: " + e);
}
An argument e of built in Exception type ArithmeticException is being
passed as an argument in the println statement.
Moreover, the following message would be displayed on execution of the
program:
See Programming Example at Page 211, 212, Java, The complete reference.
throw ThrowableInstance;
whereas,
ThrowableInstance must be an object of type Throwable or a subclass of Throwable.