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


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

Re: e==null? really?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: e==null? really?
Date Fri, 13 Jul 2012 13:11:18 -0700 (PDT)
Organization http://groups.google.com
Lines 49
Message-ID <57cde03f-92eb-48bf-9da8-ced150c0f921@googlegroups.com> (permalink)
References <c42a91b5-4e73-4647-8dc8-58b258243c2a@googlegroups.com> <jtpbc8$23s$1@dont-email.me> <jtpcfj$99l$1@dont-email.me>
NNTP-Posting-Host 69.28.149.29
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-Trace posting.google.com 1342212639 1132 127.0.0.1 (13 Jul 2012 20:50:39 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Fri, 13 Jul 2012 20:50:39 +0000 (UTC)
In-Reply-To <jtpcfj$99l$1@dont-email.me>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
User-Agent G2/1.0
X-Received-Bytes 2451
Xref csiph.com comp.lang.java.programmer:16007

Show key headers only | View raw


Eric Sosman wrote:
> markspace wrote:
> &gt; bob smith wrote:
> &gt;&gt; Is it possible to do this in Java?
> &gt;&gt;
> &gt;&gt; throw null;
> &gt;
> &gt;
> &gt; Yes. JLS:
> &gt;
> &gt; &lt;http://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.18&gt;
> &gt;
> &gt;
> &gt; &quot;throw Expression ;
> &gt;
> &gt; The Expression in a throw statement must denote either 1) a variable or
> &gt; value of a reference type which is assignable (ยง5.2) to the type
> &gt; Throwable, or 2) the null reference...&quot;
> 
>      Interesting. Reading onward, though, we find
> 
> 	&quot;If evaluation of the Expression completes normally,
> 	producing a null value, then an instance V&#39; of class
> 	NullPointerException is created and thrown instead of
> 	null. [...]&quot;
> 
> ... which leaves a bit of a mystery.  The O.P.&#39;s example was
> (fleshed out somewhat)

No mystery. The first refers to a compiler rule, the second to a runtime rule.

> 	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.

-- 
Lew

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