Originally posted by Mike Cunningham:
I'm probably overusing this forum tonight...but this should be my last question....for awhile.
Please let me know if this is correct:
If I declare that a method throws a particular error. Then I can throw that error in the method and/or I can throw any error that is more general (superclasses) to that exception.
Actually you have that backwards. You can throw
subclasses of any Exceptions you declare that your method throws, but you cannot throw superclasses, because while this statement is true due to OO-Inheritance: a subclass IS a superclass, the contrary is not.
Regarding overriding a method that throws an exception. I can throw that exception or one that is more specific (subclasses) to that exception....or I can provide the overriding method without having it throw any exception.
Am I on the right track here?
- Mike
Yes to both. You can't throw an exception that is more general than what you declared. So you can throw the exception declared in the superclass, or subclasses of that exception. You can also choose to not throw anything.