rspec/rules/S2486/csharp/rule.adoc

45 lines
795 B
Plaintext
Raw Normal View History

2020-06-30 12:48:07 +02:00
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.
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
This rule only reports on empty catch clauses that catch generic ``++Exception++``s.
2020-06-30 12:48:07 +02:00
== Noncompliant Code Example
----
string text = "";
try
{
text = File.ReadAllText(fileName);
}
catch (Exception exc) // Noncompliant
{
}
----
== Compliant Solution
----
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[]
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]