-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcexcep.java
More file actions
44 lines (43 loc) · 786 Bytes
/
cexcep.java
File metadata and controls
44 lines (43 loc) · 786 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
37
38
39
40
41
42
43
import java.io.*;
class MyException extends Exception
{
int detail;static final long serialVersionUID=111;
MyException(int x)
{
detail=x;
}
public String toString()
{
return "MyException"+"["+detail+"]";
}
}
class A
{
static void compute(int a)throws MyException
{
System.out.println("Inside compute with "+a);
if(a>10)
throw new MyException(a);
System.out.println("Normal Exit");
}
}
class Demo
{
public static void main(String []args)throws IOException
{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s1=br.readLine();
String s2=br.readLine();
int a=Integer.parseInt(s1);
int b=Integer.parseInt(s2);
A.compute(a);
A.compute(b);
}
catch(MyException e)
{
System.out.println(e);
}
}
}