Share on Google+Share on Google+

Use of Throwable Class

Advertisement
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

Advertisements

Posted on: July 3, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.