-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEcpetionMain.java
More file actions
50 lines (38 loc) · 837 Bytes
/
Copy pathEcpetionMain.java
File metadata and controls
50 lines (38 loc) · 837 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
44
45
46
47
48
49
50
package test;
class Excep extends Exception
{
/* To create user defined exception instead of system
* defined we should create class which must be a child of Exception class
* */
private String s;
Excep(String s1)
{
s = s1;
}
String info()
{
return s;
}
}
class AB
{
void f1() throws Excep//We can write throws only before Exception class or its child class
{
throw new Excep("In normal class");//Excep class object creation i.e. error occurred.
}
}
public class EcpetionMain
{
public static void main(String[] args)
{
AB obj = new AB();
try
{
//throw new Excep("In try block");
obj.f1();
}catch(Excep e)//first e is reference then after catching object from try block it becomes object
{
System.out.println(e.info());//function calling by objectname.functionname
}
}
}