-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathApp.java
More file actions
39 lines (33 loc) · 1.17 KB
/
Copy pathApp.java
File metadata and controls
39 lines (33 loc) · 1.17 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
import java.util.InputMismatchException;
import java.util.Scanner;
public class App {
public static void main(String[] args) throws Exception {
// TryCatchDemo.demoTryCatch();
// TryCatchDemo.demoTryFinally();
// TryCatchDemo.demoTryCatchFinally();
//TryCatchDemo.nestedTrycatch();
//TryCatchDemo.multiCatchBlock();
ThrowDemo.validate();
ThrowsDemo.getAge();
//Custom exception
try {
int age = inputAge();
System.out.println("Tuổi đã nhập: " + age);
} catch (AgeCheckingException e) {
System.out.println(e.getMessage());
}
//ArrayDemo.createArray();
}
static int inputAge() throws AgeCheckingException {
Scanner scanner = new Scanner(System.in);
System.out.print("Hãy nhập tuổi nhân viên: ");
int age = 0;
try {
age = scanner.nextInt();
if (age < 0) throw new AgeCheckingException("tuổi không được nhỏ hơn 0.");
} catch (InputMismatchException e) {
throw new AgeCheckingException("tuổi phải là một số.");
}
return age;
}
}