Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: e==null? really? Date: Fri, 13 Jul 2012 10:48:13 -0400 Organization: A noiseless patient Spider Lines: 41 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 13 Jul 2012 14:48:19 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="d3779b2c4a3397eb5709eec94bad057a"; logging-data="9525"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1823jbzV43IeaR0J5r0Q/iW" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: Cancel-Lock: sha1:4x92LNo0/l+zfWtjjVVqSrcAWm8= Xref: csiph.com comp.lang.java.programmer:15997 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: > > > > > "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 esosman@ieee-dot-org.invalid