Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: "javax.swing.JSnarker" Newsgroups: comp.lang.java.programmer Subject: Re: e==null? really? Date: Fri, 13 Jul 2012 17:01:49 -0400 Organization: media lab? Lines: 34 Message-ID: References: <57cde03f-92eb-48bf-9da8-ced150c0f921@googlegroups.com> NNTP-Posting-Host: n6+F6zUqqKEt240Nz306RA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: NewsTap/3.5.5 (iPhone/iPod Touch) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:16009 On 13/07/2012 4:55 PM, Joerg Meier wrote: > On Fri, 13 Jul 2012 13:11:18 -0700 (PDT), Lew wrote: > >>> try { >>> throw null; >>> } catch (Exception e) { >>> // e is null here! >>> } > >>> ... but according to the JLS that shouldn't have happened. Bug? >> It's no more a bug than that you might get a 'ClassCastException' when you cast >> a value to another type. The compiler allows what the runtime sometimes >> doesn't. > > And there's really no way around that - Exception e = null; if > (externalCondition()) e = new Exception(); throw e; - can't very well > complain about that at compile time for arbitrary definitions of > externalCondition(). Well, there is one; "throw e;" *could* have been specified to compile into what you presently get by compiling: if (e == null) throw new NullPointerException(); else throw e; -- public final class JSnarker extends JComponent A JSnarker is an NNTP-aware component that asynchronously provides snarky output when the Ego.needsPuncturing() event is fired in cljp.