rspec/rules/S1160/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

71 lines
1.6 KiB
Plaintext

== Why is this an issue?
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.
=== Noncompliant code example
[source,java]
----
public void delete() throws IOException, SQLException { // Noncompliant
/* ... */
}
----
=== Compliant solution
[source,java]
----
public void delete() throws SomeApplicationLevelException {
/* ... */
}
----
=== 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)
=== Message
Refactor this method to throw at most one checked exception instead of: {Ex1, Ex2, Ex3, etc.}
'''
== Comments And Links
(visible only on this page)
=== on 29 Jul 2013, 15:20:34 Freddy Mallet wrote:
Is implemented by \http://jira.codehaus.org/browse/SONARJAVA-248
=== on 29 Jul 2013, 23:48:51 Ann Campbell wrote:
There's no compliant example
=== on 31 Jul 2013, 16:24:16 Dinesh Bolkensteyn wrote:
'quickly' is a magic filler word ;-)
=== on 31 Jul 2013, 17:10:16 Dinesh Bolkensteyn wrote:
\[~freddy.mallet]
It seems that the checkstyle rule verifies the number of throws *statements*?
Are you sure this is a replacement?
=== on 21 Aug 2015, 15:17:03 Ann Campbell wrote:
FYI [~tamas.vajk] I've set C# to targeted on this rule
endif::env-github,rspecator-view[]