Java Exception Handling Example
Chapter:
Exception Handling
Last Updated:
19-04-2016 13:22:02 UTC
Program:
/* ............... START ............... */
import java.util.Scanner;
public class JavaExceptionHandlingExample {
public static void main(String[] args) {
int a, b, result;
Scanner input = new Scanner(System.in);
System.out.println("Input two integers");
a = input.nextInt();
b = input.nextInt();
try {
result = a / b;
System.out.println("Result = " + result);
}
catch (ArithmeticException e) {
System.out.println("Exception caught: Division by zero.");
}
}
}
/* ............... END ............... */
Output
Notes:
-
Exceptions are errors which occur when the program is executing.
Tags
Java Exception Handling, Java