Home Tutorial Java Core Use of Throwable Class

 
 

Share on Google+Share on Google+
Use of Throwable Class
Posted on: July 3, 2010 at 12:00 AM
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
Advertisement

Related Tags for Use of Throwable Class:


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.

Posted on: July 3, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com