From 6b412692545a1e4dc0b4ad172972d2937799caec Mon Sep 17 00:00:00 2001 From: kurnakovv Date: Fri, 10 Oct 2025 16:09:49 +0900 Subject: [PATCH] Add code example for CA2219 rule (#49062) --- .../code-analysis/quality-rules/ca2219.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2219.md b/docs/fundamentals/code-analysis/quality-rules/ca2219.md index f55087c355f91..7efa0023a1582 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2219.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2219.md @@ -10,6 +10,8 @@ helpviewer_keywords: - CA2219 author: gewarren ms.author: gewarren +dev_langs: +- CSharp --- # CA2219: Do not raise exceptions in exception clauses @@ -37,6 +39,20 @@ When an exception is raised in a filter clause, the runtime silently catches the To fix this violation of this rule, do not explicitly raise an exception from a `finally`, filter, or fault clause. +## Example + +```csharp +try +{ + // ... +} +finally +{ + // This code violates the rule. + throw new Exception(); +} +``` + ## When to suppress warnings Do not suppress a warning for this rule. There are no scenarios under which an exception raised in an exception clause provides a benefit to the executing code.