-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionHandling.java
More file actions
67 lines (63 loc) · 2.13 KB
/
ExceptionHandling.java
File metadata and controls
67 lines (63 loc) · 2.13 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.company;
//import java.util.Scanner;
public class ExceptionHandling {
public static void main(String[] args) {
/* Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int a,b;
a = sc.nextInt();
b = sc.nextInt();
try {
int c = a/b;
System.out.println("Result = " + c);
}
catch (ArithmeticException e)
{
System.out.println("Can't divide a number by Zero");
}
try {
int num = Integer.parseInt("chinmay");
System.out.println(num);
}
catch (NumberFormatException e) {
System.out.println("Number format exception");
}
try {
int [] a = new int[4];
a[7] = 9;
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("You have chosen non existing index in array");
}
try {
try {
int num = Integer.parseInt("Chinmay");
System.out.println(num);
} catch (NumberFormatException e) {
System.out.println("Number format exception");
} try {
int [] a = new int[5];
a[7] = 67;
}catch (Exception e) {
System.out.println("Handled");
}
System.out.println("Other Statement");
} catch (Exception e) {
System.out.println("Handled and recovered");
}
try {
int num = Integer.parseInt("Chinmay");
System.out.println(num);
} catch (NumberFormatException e) {
System.out.println("Number format exception");
}catch (Exception e) {
System.out.println("Handled");
}
System.out.println("Other Statement"); */
try {
int num = Integer.parseInt("Chinmay");
System.out.println(num);
} finally {
System.out.println("Other Statement");
}
}
}