Exception declaration with Method overriding
If a language supports Exception Declaration, this is how it likely works with method overriding.
Case 1: Super class doesn't declare an exception
Sub class overridden method:
- cannot declare a Checked Exceptions but
- can declare an Unchecked Exceptions.
Case 2: Super class declares an exception
Sub class overridden method
- can declare
- same exception
- subclass exception (Variance = covariant)
- or no exception but
- cannot declare parent exception