Java program on Exceptions with getMessage() method
EXCEPTION:
An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.
PROGRAM:
public class GetMessage {
public static void main(String[] args) {
try {
int a = 5, b = 0, c = a / b;
System.out.println(c);
} catch (Exception e) {
System.out.println("Exception caught\n" + e.getMessage());
}
}
}
public static void main(String[] args) {
try {
int a = 5, b = 0, c = a / b;
System.out.println(c);
} catch (Exception e) {
System.out.println("Exception caught\n" + e.getMessage());
}
}
}
OUTPUT:
Exception caught/ by zero