Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 946dd0f

Browse files
Add files via upload
1 parent fd8185b commit 946dd0f

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

‎NoMatchFoundException.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import java.io.*;
2+
/**
3+
* NoMatchFoundException
4+
*/
5+
6+
@SuppressWarnings("serial")
7+
class myException extends Exception{
8+
String s;
9+
myException(String s)
10+
{
11+
this.s=s;
12+
}
13+
public String toString()
14+
{
15+
return("My Exception["+s+"] not present");
16+
}
17+
}
18+
class NoMatchFoundException {
19+
static void check(String s,String city[])throws myException
20+
{
21+
int flag=0;
22+
for(int i=0;i<city.length;i++)
23+
{
24+
if(s.compareToIgnoreCase(city[i])==0)
25+
{
26+
flag=1;
27+
}
28+
}
29+
if(flag==0)
30+
{
31+
throw new myException(s);
32+
}
33+
else{
34+
System.out.println("Normal Exit");
35+
}
36+
}
37+
public static void main(String[] args)throws IOException {
38+
String city[];
39+
System.out.println("Number of cities:");
40+
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
41+
int n=Integer.parseInt(br.readLine());
42+
city=new String[n];
43+
System.out.println("Enter cities:");
44+
for(int i=0;i<n;i++)
45+
{
46+
city[i]=br.readLine();
47+
}
48+
try{
49+
check("Kolkata",city);
50+
51+
}
52+
catch (myException e) {
53+
System.out.println("Caught"+e);
54+
}
55+
}
56+
57+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /