-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTryCatchFinallyExample.java
More file actions
30 lines (26 loc) · 903 Bytes
/
TryCatchFinallyExample.java
File metadata and controls
30 lines (26 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.javaexperiments;
import java.util.InputMismatchException;
import java.util.Scanner;
/**
* Exception handling is the process of responding to the occurrence, during computation, of exceptions
* anomalous or exceptional conditions requiring special processing often changing the normal flow of program execution.
* */
public class TryCatchFinallyExample {
public static void main(String[] args) {
try {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
System.out.println(x/y);
}
catch (ArithmeticException ae) {
System.out.println(ae);
}
catch (InputMismatchException e) {
System.out.println(e);
}
finally {
System.out.println("Exception Handling is the best mechanism of handling errors.");
}
}
}