2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
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
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2020-06-30 12:48:07 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,csharp]
|
2020-06-30 12:48:07 +02:00
|
|
|
----
|
|
|
|
string text = "";
|
|
|
|
try
|
|
|
|
{
|
|
|
|
text = File.ReadAllText(fileName);
|
|
|
|
}
|
|
|
|
catch (Exception exc) // Noncompliant
|
|
|
|
{
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2020-06-30 12:48:07 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,csharp]
|
2020-06-30 12:48:07 +02:00
|
|
|
----
|
|
|
|
string text = "";
|
|
|
|
try
|
|
|
|
{
|
|
|
|
text = File.ReadAllText(fileName);
|
|
|
|
}
|
|
|
|
catch (Exception exc)
|
|
|
|
{
|
|
|
|
logger.Log(exc);
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Exceptions
|
2020-06-30 12:48:07 +02:00
|
|
|
|
|
|
|
When a block contains a comment, it is not considered to be empty.
|
|
|
|
|
|
|
|
include::../see.adoc[]
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== Message
|
|
|
|
|
|
|
|
Handle the exception or explain in a comment why it can be ignored.
|
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== 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[]
|
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|