-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava_Try_Catch_Finally.java
More file actions
32 lines (29 loc) · 1003 Bytes
/
Java_Try_Catch_Finally.java
File metadata and controls
32 lines (29 loc) · 1003 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
31
32
public class Java_Try_Catch_Finally{
public static void main(String []args){
int i = Integer.parseInt(args[0]);
System.out.println(method(i));
}
static String method(int i){
try{
System.out.println("Inside the try block");
if(i!=0 && i%2==0){
i += 10;
return "Even";
// System.out.println("Value of i = "+i);
}
else throw new Exception("Exception occured.");
}catch (Exception e){
System.out.println("Inside the catch block");
if(i!=0){
i += 20;
return "Not even";
}
else throw new Exception("Another exception.");
}finally{
System.out.println("Inside the finally block");
return "Zero and value of i = "+i;
}
//System.out.println("After finally");
//return Integer.toBinaryString(55);
}
}