-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser-defined Exception.java
More file actions
41 lines (39 loc) · 1 KB
/
User-defined Exception.java
File metadata and controls
41 lines (39 loc) · 1 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
// To see if entered number is 5, 6 or 7
import java.util.*;
class NumberException extends Exception
{
NumberException(String str)
{
super(str);
}
}
class Handle
{
public static void main(String a[])
{
int s = 0;
boolean continueInput = true;
do
{
try
{
Scanner sc = new Scanner(System.in);
System.out.println("\nEnter the number");
s = sc.nextInt();
if (s == 5 || s == 6 || s == 7)
{
System.out.println("Valid input");
}
else
{
NumberException e = new NumberException("Incorrect Input. Please try again.");
throw e;
}
continueInput = false;
} catch (NumberException e) {
System.out.println("Exception is : " + e);
}
}
while (continueInput);
}
}