Attention:
Subclasses override parent class methods to throw exceptions that are consistent with the parent class, or do not throw exceptions.
Subclasses overriding the parent class method throws an exception that cannot go beyond the scope of the parent class.
The overriding method cannot throw a new inspected exception or a more general exception than the overridden method, and can throw a non-inspected exception (the parent class throws only the exceptionthat is being inspected). For example: A method of the parent class throws a IOException exception, overriding the method cannot throw exception, can only throw a IOException subclass exception, or throw a non-examined exception. Error and RuntimeException and their subclasses belong to non-inspected exceptions (unchecked), and other exceptions are examined exceptions (checked).
1 classA {2 Public voidFun ()throwsException {3 4 } 5 } 6 classBextendsA {7 Public voidFun ()throwsIOException, RuntimeException {8 9 } Ten}
The exception thrown by the parent class contains all exceptions, which are spelled correctly.
1 classA {2 Public voidFun ()throwsRuntimeException {3 4 } 5 } 6 classBextendsA {7 Public voidFun ()throwsIOException, RuntimeException {8 9 } Ten}
Subclass IOException is out of the category of the exception of the parent class, the above syntax is wrong.
1 classA {2 Public voidFun ()throwsIOException {3 4 } 5 } 6 classBextendsA {7 Public voidFun ()throwsIOException, RuntimeException, arithmeticexception {8 9 } Ten}
RuntimeException is not part of the IO category, beyond the category of the parent category. RuntimeException and ArithmeticException are run-time exceptions, and subclasses override methods can throw any run-time exceptions. So the above wording is correct.
Resources
An issue that throws an exception when overriding a method in inheritance
Exception thrown when Java exception override method