rspec/rules/S1162/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

54 lines
1.4 KiB
Plaintext

== Why is this an issue?
The purpose of checked exceptions is to ensure that errors will be dealt with, either by propagating them or by handling them, but some believe that checked exceptions negatively impact the readability of source code, by spreading this error handling/propagation logic everywhere.
This rule verifies that no method throws a new checked exception.
=== Noncompliant code example
[source,java]
----
public void myMethod1() throws CheckedException {
...
throw new CheckedException(message); // Noncompliant
...
throw new IllegalArgumentException(message); // Compliant; IllegalArgumentException is unchecked
}
public void myMethod2() throws CheckedException { // Compliant; propagation allowed
myMethod1();
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this "throw" statement.
'''
== Comments And Links
(visible only on this page)
=== on 29 Jul 2013, 16:06:35 Freddy Mallet wrote:
Is implemented by \http://jira.codehaus.org/browse/SONARJAVA-250
=== on 31 Jul 2013, 13:41:08 Dinesh Bolkensteyn wrote:
Not be used is a bit strong, as you're still allowed to catch java.io.IOException for example.
It's just that it should not be part of the API
=== on 19 Aug 2013, 07:35:18 Dinesh Bolkensteyn wrote:
Removed 'Java' from covered languages, as we finally postponed the implementation.
endif::env-github,rspecator-view[]