Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #16009

Re: e==null? really?

From "javax.swing.JSnarker" <gharriman@boojum.mit.edu>
Newsgroups comp.lang.java.programmer
Subject Re: e==null? really?
Date 2012-07-13 17:01 -0400
Organization media lab?
Message-ID <jtq2br$2uj$1@speranza.aioe.org> (permalink)
References <c42a91b5-4e73-4647-8dc8-58b258243c2a@googlegroups.com> <jtpbc8$23s$1@dont-email.me> <jtpcfj$99l$1@dont-email.me> <57cde03f-92eb-48bf-9da8-ced150c0f921@googlegroups.com> <u0u3deibmi0q$.1aiqvfhru9gi6$.dlg@40tude.net>

Show all headers | View raw


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&#39;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.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

e==null?  really? bob smith <bob@coolfone.comze.com> - 2012-07-13 07:18 -0700
  Re: e==null?  really? markspace <-@.> - 2012-07-13 07:29 -0700
    Re: e==null?  really? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-13 10:48 -0400
      Re: e==null?  really? markspace <-@.> - 2012-07-13 08:22 -0700
        Re: e==null?  really? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-07-13 09:35 -0700
      Re: e==null?  really? Lew <lewbloch@gmail.com> - 2012-07-13 13:11 -0700
        Re: e==null?  really? Joerg Meier <joergmmeier@arcor.de> - 2012-07-13 22:55 +0200
          Re: e==null?  really? "javax.swing.JSnarker" <gharriman@boojum.mit.edu> - 2012-07-13 17:01 -0400
    Re: e==null?  really? Lew <lewbloch@gmail.com> - 2012-07-13 13:09 -0700
  Re: e==null?  really? Roedy Green <see_website@mindprod.com.invalid> - 2012-07-13 12:09 -0700
    Re: e==null?  really? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-07-13 23:06 +0200
      Re: e==null?  really? Roedy Green <see_website@mindprod.com.invalid> - 2012-07-14 06:30 -0700

csiph-web