classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Declaring RuntimeExceptions?


From: David Holmes
Subject: RE: Declaring RuntimeExceptions?
Date: Fri, 12 Sep 2003 11:06:02 +1000

> So, should a java compiler accept the following?
>
> // java.awt.HeadlessException
> //   extends java.lang.UnsupportedOperationException
> //     extends java.lang.RuntimeException
>
> class Foo
> {
>   void meth() throws java.awt.HeadlessException { }
> }
>
> class Bar
>   extends Foo
> {
>   void meth() { }
> }

The code is valid in that its okay for a subclass to declare fewer
exceptions on an overriding method - checked or unchecked. Hence
Bar.meth is correctly defined and must be accepted by any compiler.

However, a compiler could complain that Foo.meth can never throw the
declared HeadlessException (as it should for a checked exception) and
refuse to compile it. I think it would be a bit over-zealous, though
not "illegal", to do so.

David Holmes





reply via email to

[Prev in Thread] Current Thread [Next in Thread]