Community
Participate
Working Groups
If a public or protected method declares an exception that is not actually thrown, but an overriding method in a subclass DOES throw the exception, the exception declaration should not produce a warning in the superclass. Example: public class Foo { // Produces a warning, but shouldn't public void someMethod() throws SomeException { // default implementation does nothing } // Produces a warning, but shouldn't public void anotherMethod() throws SomeException { // default implementation does nothing } } public class Bar extends Foo { public someMethod() throws SomeException { boolean someResult = doSomething(); if (!someResult) { throw SomeException(); } } } public class Baz extends Bar { public void anotherMethod() throws SomeException { boolean anotherResult = doSomethingElse(); if (!anotherResult ) { throw SomeException(); } } }
Known limitation. Rather than doing what is suggested here, we should consider documented exception in Javadoc (@throws).