gudii9
asked on
null output
Hi,
why above program generates null output or no output.
please advise
public class Exceptions {
public void test() throws NullPointerException {
NullPointerException e = new NullPointerException("");
throw e;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
// int arr[] = { 1, 2, 3, 4, 5 };
try {
// System.out.println(arr[5]);
//System.out.println("next");
// } catch (NullPointerException e) {
Exceptions obj = new Exceptions();
obj.test();
}
// System.out.println("in between try and catch");
// catch (ArrayIndexOutOfBoundsException e) {
// catch (NullPointerException e) {
catch (Exception e) {
// TODO: handle exception
System.out.println(e.getMessage());
}
// System.out.println("hi");
}
}
why above program generates null output or no output.
please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
public class Exceptions {
public void test() throws NullPointerException {
NullPointerException e = new NullPointerException("hiiii");
throw e;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
// int arr[] = { 1, 2, 3, 4, 5 };
try {
// System.out.println(arr[5]);
//System.out.println("next");
// } catch (NullPointerException e) {
Exceptions obj = new Exceptions();
obj.test();
}
// System.out.println("in between try and catch");
// catch (ArrayIndexOutOfBoundsException e) {
// catch (NullPointerException e) {
catch (Exception e) {
// TODO: handle exception
System.out.println(e.getMessage());
}
// System.out.println("hi");
}
}
above gave below correct output
hiiii
ASKER