RCS1236: Use exception filter
Properties
Property | Value |
---|---|
Default Severity | Info |
Minimum language version | 6.0 |
Examples
Example #1
diagnostic.cs
try
{
}
catch (Exception ex)
{
if (!(ex is InvalidOperationException))
{
throw;
}
return;
}
fix.cs
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.