The Philosophy of Nothing

Reinier Zwitserloot reinier at
Wed Dec 2 08:45:19 PST 2009

The 'throws' clause of any method declaration lists *CHECKED* exceptions
that you can't throw. Thus, "throws Nothing" indicates that the method may
throw any unchecked exception, like all methods can, and may also throw any
instance of Nothing.

That last bit is trivially true for two reasons:

1. There are no instances of nothing. Therefore, granting any method the
ability to throw instances of Nothing is irrelevant.

2. Nothing is an unchecked exception type, as it is a subtype of either
RuntimeException or Error (it is in fact, both - Nothing is a subtype of
everything). This is consistent with existing spec, see JLS 11.2:

"The *unchecked exceptions classes* are the class RuntimeException and its
subclasses, and the class Error and its subclasses."

therefore, writing "throws Nothing" is as trivial as "throws
NullPointerException". The compiler can run right past such a 'throws'
clause, as it is effectively meaningless.

If you're falling over the verbiage here (that "throws Nothing" seems to
indicate that a method must not throw anything if you don't think about it
for very long) I suggest you get over it. Confusion in frivolously
constructed examples does not trump being compatible with other JVM
languages that already have this concept, as well as having a natural term
for situations where this type WILL see real-life usage, such as in return
types and generics.

--Reinier Zwitserloot

On Wed, Dec 2, 2009 at 5:26 PM, Paul Benedict <pbenedict at> wrote:

> Neal,
> On Wed, Dec 2, 2009 at 10:07 AM, Neal Gafter <neal at> wrote:
> > On Wed, Dec 2, 2009 at 7:59 AM, Paul Benedict <pbenedict at>
> wrote:
> >>
> >> Does the spec prevent defining method that can neither return nor throw?
> >>
> >> public Nothing func() throws Nothing { }
> >
> > No, because Java has unchecked exceptions, and for other reasons that
> will
> > be more clear when part b (0.6b) is published.
> >
> > I can't imagine what the value would be of adding such restrictions to
> the
> > specification or compiler.
> If a method cannot return nor throw, I would expect this to be an
> obvious compilation error. Note this example has nothing to do with
> closures, but just a normal method declaration.
> Well, I'll have to be patient and wait for 0.6b to explain. I am
> hoping that Nothing is used consistently. Thanks, Neal.
> Paul
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the closures-dev mailing list