-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultipleExceptions.java
More file actions
23 lines (20 loc) · 880 Bytes
/
Copy pathMultipleExceptions.java
File metadata and controls
23 lines (20 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.InputMismatchException;
import java.util.Scanner;
public class MultipleExceptions {
public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
System.out.print("Enter an integer: ");
int number = scanner.nextInt();
int result = 100 / number; // Might throw ArithmeticException
System.out.println("Result: " + result);
} catch (ArithmeticException e) {
System.out.println("Error: Division by zero is not allowed.");
} catch (InputMismatchException e) {
System.out.println("Error: Please enter a valid integer.");
} catch (Exception e) {
System.out.println("An unexpected error occurred: " + e.getMessage());
} finally {
System.out.println("Program execution completed.");
}
}
}