27 lines
746 B
Plaintext
27 lines
746 B
Plaintext
Declaring that a method ``++throws++`` an exception type that it doesn't is like a wart on the code: seemingly ugly but harmless. Unfortunately, like warts, those un-thrown exceptions will spread as each calling method is forced to deal with the ``++throws++`` declaration. Eventually, your code is so covered in warts that you can't see the form beneath.
|
|
|
|
|
|
Which is why this rule raises an issue when a method declares an exception type it doesn't actually throw.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,text]
|
|
----
|
|
public void output(String text) throws NumberFormatException { // Noncompliant
|
|
System.out.println(text);
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
[source,text]
|
|
----
|
|
public void output(String text) {
|
|
System.out.println(text);
|
|
}
|
|
----
|
|
|
|
|