Skip to content

Latest commit

 

History

History
51 lines (39 loc) · 1.13 KB

RCS1236.md

File metadata and controls

51 lines (39 loc) · 1.13 KB

RCS1236: Use exception filter

Property Value
Id RCS1236
Severity Info
Minimum language version 6.0

Example

Code with Diagnostic

try
{
}
catch (Exception ex)
{
    if (!(ex is InvalidOperationException)) // RCS1236
    {
        throw;
    }

    return;
}

Code with Fix

try
{
}
catch (Exception ex) when (ex is InvalidOperationException)
{
    return;
}

Remarks

The accepted answer from Stack Overflow states:

"If there is an exception thrown within the filter, then that exception will be silently swallowed and the filter simply fails."

It is impossible to definitely detect if an exception can be thrown within an expression.

So the expression is considered as the one that can throw an exception if it contains method call that meets one of the following requirements:

  • Its name starts with ThrowIf.
  • Its XML comment contains <exception> element. (Generated with DotMarkdown)