-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx19Exception.java
More file actions
26 lines (22 loc) · 770 Bytes
/
Copy pathEx19Exception.java
File metadata and controls
26 lines (22 loc) · 770 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
package JavaEntry;
public class Ex19Exception {
static void checkPass(int age){
if(age > 18){
System.out.println("You can enter");
}else{
throw new ArithmeticException("You are not allow to enter");
}
}
public static void main(String[] args){
try{
int[] numberList = {1, 2, 3, 4};
System.out.println(numberList[0]); // This will print
checkPass(10);
System.out.println(numberList[10]); // This will not print and stop the whole program, to avoid use exception
}catch(Exception e){
System.out.println("Something went wrong, " + e);
}finally{
System.out.println("The 'try catch' is finished");
}
}
}