# Remove Unnecessary Thrown Exceptions on Method Signatures
# Description
Removes the following exceptions on method signatures:
- Exceptions that are subtypes of already thrown exceptions
- Exceptions that are thrown more than once
- Exceptions that are inheriting from
RuntimeException
# Benefits
Improves the readability by removing code that adds no information on the method signature.
# Tags
Tags
# Code Changes
# Declaring a throws exception whose parent type is already thrown
Pre
public void throwingChildAndParent() throws ChildException, ParentException {
...
}
Post
public void throwingChildAndParent() throws ParentException {
...
}
# Declaring a throws exceptions more than once
Pre
public void throwingTheSameExceptionTwice() throws Exception, Exception {
...
}
Post
public void throwingTheSameExceptionTwice() throws Exception {
...
}
# Declaring a throws Unchecked exception
Pre
public void throwingRuntimeException() throws ArrayIndexOutOfBoundsException {
...
}
Post
public void throwingRuntimeException() {
...
}
Use a Java Refactoring Tool
Automate this Refactoring system-wide
You can apply this refactoring for free with the jSparrow Eclipse IDE plug-in.
Install the plug-in for Eclipse IDE: Eclipse Marketplace.