Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

null output

Hi,

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");
	}

}

Open in new window


why above program generates null output or no output.

please advise
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

make sense
Avatar of gudii9

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");
	}

}

Open in new window


above gave below correct output
hiiii