Throw Clause: Sensitivity: Internal & Restricted
Throw Clause: Sensitivity: Internal & Restricted
Throw Clause
At times you may want to throw the exceptions explicitly which can be done using the
throw keyword
Column A Column B
a) An exception is a) Used to throw an exception explicitly
b) Throwable b) Caused by Dividing an integer by zero
c) ArithmeticException is c) An event that can disrupt the normal flow
of instructions
d) Catch Block d) This class is at the top of exception
hierarchy
e) “throw” is e) Exception Handler
import java.io.*;
class ThrowTester {
void method() throws IOException {
throw new IOException(“Method Error");
}
But there may be cases where we may have to define our own exceptions which are
application specific
For ex: If we have are creating an application for handling the database of eligible voters, the
age should be greater than or equal to 18
In this case, we can create a user defined exception, which will be thrown in case the age
entered is less than 18
The user defined exception class should extend from the Exception class and its
subclass
Contd..
String getMessage() – used to get the customized message from the exception.