I have two questions :
In both cases, it's because the base method you're overriding has set the contract with the calling code; if you could add to the checked exceptions that the method may throw, you'd be breaking the contract.
Consider a class Base
with a method foo
that throws a checked exception SomeException
. You also have a Derived
which derives from Base
and overrides foo
. Code in App
is using a Base b
variable but initializing it with a new instance of Derived
, and calling b.foo()
. The contract is that foo
throws just SomeException
; throwing anything else breaks the contract.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With