- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionClass.java
More file actions
Latest commit
44 lines (41 loc) · 1.11 KB
/
Copy pathExceptionClass.java
File metadata and controls
44 lines (41 loc) · 1.11 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
importjava.util.Scanner;
classMyExceptionextendsException{
@Override
publicStringtoString() {
return"I am toString()";
}
@Override
publicStringgetMessage() {
return"I am getMessage()";
}
}
classMaxAgeExceptionextendsException{
@Override
publicStringtoString() {
return"Age cannot be greater than 125";
}
@Override
publicStringgetMessage() {
return"Make sure that the value of age entered is correct";
}
}
publicclassExceptionClass {
publicstaticvoidmain(String[] args) {
inta;
Scannersc = newScanner(System.in);
a = sc.nextInt();
if (a<9){
try{
// throw new MyException();
thrownewArithmeticException("This is an exception");
}
catch (Exceptione){
System.out.println(e.getMessage());
System.out.println(e.toString());
e.printStackTrace();
System.out.println("Finished");
}
System.out.println("Yes Finished");
}
}
}