0

I am reading Java Complete Reference by Helbert Schildt where he shows this example using exceptions.

class ThrowDemo {
       static void demoproc() {
         try {
           throw new NullPointerException("demo");
         } catch(NullPointerException e) {
           System.out.println("Caught inside demoproc.");
           throw e; // rethrow the exception
         }
       }
       public static void main(String args[]) {
         try {
           demoproc();
         } catch(NullPointerException e) {
           System.out.println("Recaught: " + e);
         }
       } 
}

Why does not method demoproc() have keyword throws in it's signature when it can potentially throw exception in the catch clause?

1 Answers1

0

NullPointerException is un-checked exception. You only need delcare the exception in method signature when it is checked exception.

xingbin
  • 27,410
  • 9
  • 53
  • 103