rspec/rules/S2486/csharp/rule.adoc

57 lines
951 B
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)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]