forked from avinashbest/java-coding-ninjas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionHandling.java
More file actions
27 lines (25 loc) · 769 Bytes
/
Copy pathExceptionHandling.java
File metadata and controls
27 lines (25 loc) · 769 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
package exceptionHandling;
public class ExceptionHandling {
public static void main(String[] args) {
int a = 10;
int b = 0;
try {
divide(a, b);
System.out.println("Within Try");
} catch (DivideByZeroException e) {
System.out.println("Divide by 0 Exception raised");
e.printStackTrace();
} catch (Exception e) {
System.out.println("Generic Exception");
} finally {
System.out.println("Finally");
}
System.out.println("main() continues");
}
private static int divide(int a, int b) throws DivideByZeroException {
if (b == 0) {
throw new DivideByZeroException();
}
return a / b;
}
}