[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Declaring RuntimeExceptions?
From: |
Stephen Crawley |
Subject: |
Re: Declaring RuntimeExceptions? |
Date: |
Fri, 12 Sep 2003 11:03:22 +1000 |
Sascha,
> 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() { }
> }
Yes it should.
Refer to the JLS Section 8.4.4. The last two paragraphs read as follows:
A method that overrides or hides another method (§8.4.6), including
methods that implement abstract methods defined in interfaces, may
not be declared to throw more checked exceptions than the overridden
or hidden method.
More precisely, suppose that B is a class or interface, and A is a
superclass or superinterface of B, and a method declaration n in B
overrides or hides a method declaration m in A. If n has a throws
clause that mentions any checked exception types, then m must have
a throws clause, and for every checked exception type listed in the
throws clause of n, that same exception class or one of its superclasses
must occur in the throws clause of m; otherwise, a compile-time error
occurs.
Note that these rules are for >>checked<< exceptions only; i.e. exception
classes that are NOT subtypes of Error or RuntimeException.
> javac 1.4.1 compiles this code, but gcj 3.2 complains about the throws
> clause (of *Foo*.meth, which is a bit misleading).
gcj 3.2 is clearly wrong, IMO.
-- Steve
- Declaring RuntimeExceptions?, Sascha Brawer, 2003/09/11
- Re: Declaring RuntimeExceptions?, Brian Jones, 2003/09/11
- Re: Declaring RuntimeExceptions?, Ingo Prötel, 2003/09/11
- Re: Declaring RuntimeExceptions?, Otavio Pereira, 2003/09/11
- RE: Declaring RuntimeExceptions?, David Holmes, 2003/09/11
- Re: Declaring RuntimeExceptions?, Eric Blake, 2003/09/11
- Re: Declaring RuntimeExceptions?, Sascha Brawer, 2003/09/11
- Re: Declaring RuntimeExceptions?,
Stephen Crawley <=
- RE: Declaring RuntimeExceptions?, David Holmes, 2003/09/11
- Re: Declaring RuntimeExceptions?, Tom Tromey, 2003/09/17
Re: Declaring RuntimeExceptions?, Tom Tromey, 2003/09/11