CA2219 (Do not use throw in finally) documentation should suggest alternative approaches
- Dominant language
- No language data
- Stars
- 4.8k
- Forks
- 6.1k
- Avg merge
- 15h 21m
- Merged PRs (30d)
- 370
Description
### Type of issue
Missing information
### Description
The article on [CA2219: Do not raise exceptions in exception clauses](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2219) currently (as of 2025-09-03) provides only a dogmatic "you should never do this" statement but does not suggest any alternative approaches to resolve the CA warning:
------
I quote (emphasis mine):
> ## How to fix violations
> To fix this violation of this rule, do not explicitly raise an exception from a finally, filter, or fault clause.
>
> ## 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.
-------
Its easy to trigger CA2219 warnings when working with COM or PInvoke in C#, where our `finally` or `void Dispose` methods call into native methods that can/will/do fail with exceptions or runtime errors of their own; this includes C# code generated by [CsWin32](https://github.com/microsoft/CsWin32), for example.
-----
Normally I'd provide some text to be copied+pasted into the article, but such-as-it-is, I don't know what the current Best Practices advice is for "failable-finally" clauses. I did find [this related feedback suggesting passing exceptions around in locals](https://github.com/dotnet/roslyn-analyzers/issues/5869#issuecomment-2459837482) - but it offends my aesthetics. In my own software I've stopped trying to faff-around with second-order exceptions and simply call `Environment.FailFast` in event of an (unexpected) second-order exception, but I'm sure a better approach must exist.
### Page URL
https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2219
### Content source URL
https://github.com/dotnet/docs/blob/main/docs/fundamentals/code-analysis/quality-rules/ca2219.md
### Document Version Independent Id
d07c8efd-99c8-3bde-5b4b-d762d9e77e8d
### Platform Id
f5551239-15d6-1310-99f8-4573450bd87f
### Article author
@gewarren
### Metadata
* ID: a900d720-516e-d119-aba1-bb6db366774b
* PlatformId: f5551239-15d6-1310-99f8-4573450bd87f
* Service: **dotnet-fundamentals**
[Related Issues](https://github.com/dotnet/docs/issues?q=is%3Aissue+is%3Aopen+d07c8efd-99c8-3bde-5b4b-d762d9e77e8d)
Contributor guide
Assessment
This issue has not been assessed yet.