On 7/13/2012 10:29 AM, markspace wrote:
> On 7/13/2012 7:18 AM, bob smith wrote:
>> Is it possible to do this in Java?
>>
>> throw null;
>
>
> Yes. JLS:
>
> <http://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.18>
>
>
> "throw Expression ;
>
> The Expression in a throw statement must denote either 1) a variable or
> value of a reference type which is assignable (§5.2) to the type
> Throwable, or 2) the null reference..."
Interesting. Reading onward, though, we find
"If evaluation of the Expression completes normally,
producing a null value, then an instance V' of class
NullPointerException is created and thrown instead of
null. [...]"
.... which leaves a bit of a mystery. The O.P.'s example was
(fleshed out somewhat)
try {
throw null;
} catch (Exception e) {
// e is null here!
}
.... but according to the JLS that shouldn't have happened. Bug?
--
Eric Sosman
d