-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqb94.java
More file actions
36 lines (30 loc) · 746 Bytes
/
Copy pathqb94.java
File metadata and controls
36 lines (30 loc) · 746 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
//CUSTOM EXCEPTION PROGRAM
//QB 94
import java.util.*;
class MyException extends Exception {
MyException(String s) {
super(s);
}
}
class Exceptiondemo {
void compute(int a) throws MyException {
if (a > 10) {
throw new MyException(a + " is greater than 10");
} else {
System.out.println(a + " is less than 10 ");
}
}
}
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a: ");
int a = sc.nextInt();
Exceptiondemo ed = new Exceptiondemo();
try {
ed.compute(a);
} catch (MyException e) {
System.out.println(e);
}
}
}