# Remove Unnecessary Thrown Exceptions on Method Signatures

# Properties

Property Value
Rule ID RemoveUnnecessaryThrows
First seen in jSparrow version 2.7.0
Minimum Java version 1.1
Remediation cost 2 min
Links S1130

# Description

Removes the following exceptions on method signatures:

  1. Exceptions that are subtypes of already thrown exceptions
  2. Exceptions that are thrown more than once
  3. Exceptions that are inheriting from RuntimeException

# Benefits

Improves the readability by removing code that adds no information on the method signature.

# 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() {
	...
}

Automatic Application of This Rule

The automatic application of this rule is supported in the following jSparrow versions:

# Tags

1
default
You & jSparrow
default

Hey there! May I help you? 😊