-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
35 lines (29 loc) · 712 Bytes
/
Copy pathMain.java
File metadata and controls
35 lines (29 loc) · 712 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
package test;
class C
{
void f1() throws Exception
{
/* throws keyword can be only written before any function name within function any
* exception occurs this function will return back the object from where the function is called
* */
//NullPointerException np = new NullPointerException();
//throw np;
//throw new NullPointerException(); //creating exception explicitly using throw keyword
int z= 5/0;
}
}
public class Main
{
public static void main(String[] args)
{
try
{
C ob1 = new C();
ob1.f1();
}catch(Exception e)
{
System.out.println(e.toString());//It will display the class name of which error object is created
}
System.out.println("Hello");
}
}