Use of Throwable Class


 

Use of Throwable Class

This section illustrates you the use of Throwable Class.

This section illustrates you the use of Throwable Class.

Use of Throwable Class

Throwable class is the super class of all the exceptional class and error class. Only objects of this class can be thrown & caught and handled by try-catch blocks. In java you can throw exception Object which are derived from throwable class. To create your own class of throwable objects, you need to declare it as a subclass of some member of the Throwable family.

Here is the code:

public class ThrowableClass {
	public static void main(String args[]) {
		try {
			int i = 9;
			int j = 0;
			int result = i / j;
			System.out.println(result);

		} catch (Throwable t) {
			System.out.println(t);
		}
	}
}

Output:

java.lang.ArithmeticException: / by zero

Ads