47 lines
886 B
Plaintext
47 lines
886 B
Plaintext
![]() |
This rule raises an issue on logging calls inside a `catch` clause that does not pass the raised `Exception`.
|
||
|
|
||
|
include::../why-dotnet.adoc[]
|
||
|
|
||
|
== How to fix it
|
||
|
|
||
|
=== Code examples
|
||
|
|
||
|
==== Noncompliant code example
|
||
|
|
||
|
[source,csharp,diff-id=1,diff-type=noncompliant]
|
||
|
----
|
||
|
public bool Save()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
DoSave();
|
||
|
return true;
|
||
|
}
|
||
|
catch(IOException)
|
||
|
{
|
||
|
logger.LogError("Saving failed."); // Noncompliant: No specifics about the error are logged
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
----
|
||
|
|
||
|
==== Compliant solution
|
||
|
|
||
|
[source,csharp,diff-id=1,diff-type=compliant]
|
||
|
----
|
||
|
public bool Save()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
DoSave();
|
||
|
return true;
|
||
|
}
|
||
|
catch(IOException exception)
|
||
|
{
|
||
|
logger.LogError(exception, "Saving failed."); // Compliant: Exception details are logged
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
----
|
||
|
|
||
|
include::../resources-dotnet.adoc[]
|