rspec/rules/S1160/java/rule.adoc

29 lines
664 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
Using checked exceptions forces method callers to deal with errors, either by propagating them or by handling them. Throwing exceptions makes them fully part of the API of the method.
But to keep the complexity for callers reasonable, methods should not throw more than one kind of checked exception.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
public void delete() throws IOException, SQLException { // Noncompliant
/* ... */
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
public void delete() throws SomeApplicationLevelException {
/* ... */
}
----
2021-04-28 16:49:39 +02:00
== Exceptions
Overriding methods are not checked by this rule and are allowed to throw several checked exceptions.