forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustom_Ex1.java
More file actions
41 lines (34 loc) · 819 Bytes
/
Custom_Ex1.java
File metadata and controls
41 lines (34 loc) · 819 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
33
34
35
36
37
38
39
40
41
package exception;
import java.util.Scanner;
public class Custom_Ex1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
System.out.println("<< Custom Exception for checking age is valid for votiong or not. >>");
System.out.println("Enter age : ");
int a = s.nextInt();
check(a);
s.close();
}
static void check(int a) {
if (a < 18) {
try {
throw new InvalidAgeException("You are under age for voting.");
} catch (InvalidAgeException e) {
// TODO: handle exception
System.out.println(e);
}
} else {
System.out.println("You are able for voting.");
}
}
}
@SuppressWarnings("serial")
class InvalidAgeException extends Exception {
InvalidAgeException(String s) {
super(s);
}
}