-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExceptingDemo.java
34 lines (25 loc) · 887 Bytes
/
ExceptingDemo.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
public class ExceptingDemo {
public String sayHello(String str) throws Exception,IndexOutOfBoundsException{
try {
if(str==null)
throw new IndexOutOfBoundsException("null");
str=str.concat("World");
} catch (NullPointerException e) {
throw new Exception("Null pointer"); //when I throw exception here No one to catch here
}
catch (Exception e){
System.out.println("Exception occured !");
throw new Exception("Error");
}
return str;
}
public static void main(String[] args) {
ExceptingDemo exceptingDemo = new ExceptingDemo();
try {
String hello = exceptingDemo.sayHello(null);
System.out.println(hello);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}