-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionClass.java
More file actions
44 lines (41 loc) · 1.11 KB
/
ExceptionClass.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
import java.util.Scanner;
class MyException extends Exception{
@Override
public String toString() {
return "I am toString()";
}
@Override
public String getMessage() {
return "I am getMessage()";
}
}
class MaxAgeException extends Exception{
@Override
public String toString() {
return "Age cannot be greater than 125";
}
@Override
public String getMessage() {
return "Make sure that the value of age entered is correct";
}
}
public class ExceptionClass {
public static void main(String[] args) {
int a;
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
if (a<9){
try{
// throw new MyException();
throw new ArithmeticException("This is an exception");
}
catch (Exception e){
System.out.println(e.getMessage());
System.out.println(e.toString());
e.printStackTrace();
System.out.println("Finished");
}
System.out.println("Yes Finished");
}
}
}