I currently have a class that I need to extend and one method of that class that I need to override.
Assuming the following:
public BaseClass {}
public BarClass extends BaseClass {
public configure () {}
}
public FooClass extends BarClass {
@Override
public configure () {
}
}
I want to throw custom exceptions from FooClass, but haven't as yet found the magic behind doing that. If I add a throws statement to FooClass, eg.
public FooClass extends BarClass throws MyException{
@Override
public configure () {
...
throw new MyException();
}
}
javac complains that a "{" was expected on the FooClass declaration.
If I add the throws to the configure() method in FooClass, javac complains that the overridden class does not throw MyException. eg.
public FooClass extends BarClass{
@Override
public configure () throws MyException {
...
throw new MyException();
}
}
First, should I be able to throw my own exceptions on overridden methods of an extended class? If yes, what am I missing?
-David