The following program
> package bug;
>
> class SuperClass
> {
> SuperClass() throws Exception { throw new Exception(); }
> }
>
> public class Bug extends SuperClass
> {
> // Comment in the following line to make javac compile.
> // Bug() throws Exception {}
> }
leads to the following error message:
> bug/Bug.java:8: unreported exception: Exception; must be caught or
declared to be thrown
> public class Bug extends SuperClass
> ^
> 1 error
Ok, class Bug must define a constructor that
throws the same exception as the superclass
constructor does; then the program compiles.
But the error message is quite misleading, if you
do not recognize the problem.
> package bug;
>
> class SuperClass
> {
> SuperClass() throws Exception { throw new Exception(); }
> }
>
> public class Bug extends SuperClass
> {
> // Comment in the following line to make javac compile.
> // Bug() throws Exception {}
> }
leads to the following error message:
> bug/Bug.java:8: unreported exception: Exception; must be caught or
declared to be thrown
> public class Bug extends SuperClass
> ^
> 1 error
Ok, class Bug must define a constructor that
throws the same exception as the superclass
constructor does; then the program compiles.
But the error message is quite misleading, if you
do not recognize the problem.
- relates to
-
JDK-4278961 # error reporting and recovery issues in the new compiler
-
- Closed
-
-
JDK-4071337 Misleading error message when superclass constructor has throws clause
-
- Closed
-