Write a program to show the use of try statements that emphasizes the sequence
of checking for catch handler statements.
package error;
import java.util.Scanner;
public class Error {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int value1, value2;
try {
//Try block
System.out.println("Enter a value to divide by 25");
value2 = input.nextInt();
value1 = 25 / value2;
System.out.println("The answer is \t"+value1);
System.out.println("Try Block:: End");
}
catch (ArithmeticException e) {
System.out.println("ArithmeticException :: Divide by Zero!!");
}
}
}
Comments
Leave a comment