-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathNoMatchFoundException.java
57 lines (54 loc) · 1.32 KB
/
NoMatchFoundException.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.io.*;
/**
* NoMatchFoundException
*/
@SuppressWarnings("serial")
class myException extends Exception{
String s;
myException(String s)
{
this.s=s;
}
public String toString()
{
return("My Exception["+s+"] not present");
}
}
class NoMatchFoundException {
static void check(String s,String city[])throws myException
{
int flag=0;
for(int i=0;i<city.length;i++)
{
if(s.compareToIgnoreCase(city[i])==0)
{
flag=1;
}
}
if(flag==0)
{
throw new myException(s);
}
else{
System.out.println("Normal Exit");
}
}
public static void main(String[] args)throws IOException {
String city[];
System.out.println("Number of cities:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
city=new String[n];
System.out.println("Enter cities:");
for(int i=0;i<n;i++)
{
city[i]=br.readLine();
}
try{
check("Kolkata",city);
}
catch (myException e) {
System.out.println("Caught"+e);
}
}
}