June 2018
Beginner
722 pages
18h 47m
English
The throw statement consists of the keyword throw and either a variable or value of a reference type java.lang.Throwable, or the null reference. Since all the exceptions are children of java.lang.Throwable, any of the following throw statements is correct:
throw new Exception("Something happened");Exception ex = new Exception("Something happened");throw ex;Throwable thr = new Exception("Something happened");throw thr;throw null;
If null is thrown, as it is in the last statement, then JVM converts it to a NullPointerException, so these two statements are equivalent:
throw null;throw new NullPointerException;
And, just to remind you, the package java.lang does not need to be imported. You can refer to any of the package java.lang members—interface ...
Read now
Unlock full access