Java Exception Using Class Object
Chapter:
Exception Handling
Last Updated:
05-11-2016 14:10:16 UTC
Program:
/* ............... START ............... */
public class JavaExceptionUsingClassObject {
public static void main(String[] args) {
try {
int x = 1 / 0;
} catch (Exception e) {
System.out.println(e);
}
}
}
/* ............... END ............... */
Output
java.lang.ArithmeticException: / by zero
Notes:
-
In Java there are three ways to find the details of the exception .
- Using an object of java.lang.Exception
- Using public void printStackTrace() method
- Using public String getMessage() method.
Tags
Exception Using Class Object, Java, Exception Handling