I mean, in the definition. If I have a method of a class that implements an interface and I want to throw an exception, how can I do that if the interface don't have a throws declaration.
Thanks
How is the code relying on your class implementing the interface going to know that it has to handle the new exception? You have two options:
RuntimeException
, which doesn't need to be in the throws
clause. However, any code calling this method does not have to catch this exception nor does it know that it can be thrown. So be careful when using this option. Document them where possible, but you'll still face a problem when passing an object to an existing method such as a library or one that is built-in.You simply don't or throw a RuntimeException.
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