Java exception :
package com;
public class Test ...{
public static void main(String[] args) ...{
try ...{
throw new NullPointerException();
//System.out.println("Exception:"); // unreachable
} catch (NullPointerException ex) ...{
System.out.println("Exception:");
System.out.println(ex.getMessage());
}
try ...{
exceptionOne();
} catch (NullPointerException ex) ...{
System.out.println("exceptionOne:");
System.out.println(ex.getMessage());
}
try ...{
exceptionTwo();
} catch (NullPointerException ex) ...{
System.out.println("exceptionTwo:");
System.out.println(ex.getMessage());
}
// exceptionOne(); // exit main and program terminate
}
private static void exceptionOne() ...{
throw new NullPointerException();
//System.out.println("Exception:"); // unreachable
}
private static void exceptionTwo() ...{
if (true) ...{
System.out.println("ex2");
throw new NullPointerException();
}
}
}
public class Test ...{
public static void main(String[] args) ...{
try ...{
throw new NullPointerException();
//System.out.println("Exception:"); // unreachable
} catch (NullPointerException ex) ...{
System.out.println("Exception:");
System.out.println(ex.getMessage());
}
try ...{
exceptionOne();
} catch (NullPointerException ex) ...{
System.out.println("exceptionOne:");
System.out.println(ex.getMessage());
}
try ...{
exceptionTwo();
} catch (NullPointerException ex) ...{
System.out.println("exceptionTwo:");
System.out.println(ex.getMessage());
}
// exceptionOne(); // exit main and program terminate
}
private static void exceptionOne() ...{
throw new NullPointerException();
//System.out.println("Exception:"); // unreachable
}
private static void exceptionTwo() ...{
if (true) ...{
System.out.println("ex2");
throw new NullPointerException();
}
}
}
Exception:
null
exceptionOne:
null
ex2
exceptionTwo:
null