rspec/rules/S1160/java/rule.adoc

46 lines
944 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
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public void delete() throws IOException, SQLException { // Noncompliant
/* ... */
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
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.
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]