-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomException.java
39 lines (30 loc) · 991 Bytes
/
CustomException.java
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.Scanner;
class SMVDUException extends Exception {
public SMVDUException(String str) {
super(str);
}
}
public class CustomException {
public static void main(String args[]) throws SMVDUException {
Scanner sc = new Scanner(System.in);
System.out.println("Enter String ");
String a = sc.nextLine();
String b = "SMVDU";
String c = "university";
if (a.equals(b)) {
try {
throw new SMVDUException("SMVDU Exception");
} catch (SMVDUException ex) {
System.out.println(ex.getMessage());
}
System.out.println("Out Of Exception");
} else if (a.equals(c)) {
try {
throw new SMVDUException("Univerrsity Exception");
} catch (SMVDUException ex) {
System.out.println(ex.getMessage());
}
System.out.println("Out Of Exception");
}
}
}