rspec/rules/S2486/csharp/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

67 lines
1.3 KiB
Plaintext

== Why is this an issue?
When exceptions occur, it is usually a bad idea to simply ignore them. Instead, it is better to handle them properly, or at least to log them.
This rule only reports on empty catch clauses that catch generic ``++Exception++``s.
=== Noncompliant code example
[source,csharp]
----
string text = "";
try
{
text = File.ReadAllText(fileName);
}
catch (Exception exc) // Noncompliant
{
}
----
=== Compliant solution
[source,csharp]
----
string text = "";
try
{
text = File.ReadAllText(fileName);
}
catch (Exception exc)
{
logger.Log(exc);
}
----
=== Exceptions
When a block contains a comment, it is not considered to be empty.
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Handle the exception or explain in a comment why it can be ignored.
'''
== Comments And Links
(visible only on this page)
=== on 23 Mar 2015, 10:07:39 Tamas Vajk wrote:
\[~ann.campbell.2], Could you please check this subtask?
=== on 23 Mar 2015, 11:31:17 Ann Campbell wrote:
\[~tamas.vajk], there's no need to repeat the description in the subtask when it's the same (so I've removed it). Otherwise, this looks great. :-)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]