A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2201 below:

CA2201: Do not raise reserved exception types (code analysis) - .NET

Property Value Rule ID CA2201 Title Do not raise reserved exception types Category Usage Fix is breaking or non-breaking Breaking Enabled by default in .NET 9 No Cause

A method raises an exception type that's too general or that's reserved by the runtime.

Rule description

The following exception types are too general to provide sufficient information to the user:

The following exception types are reserved and should be thrown only by the common language runtime:

Don't throw general exceptions

If you throw a general exception type, such as Exception or SystemException, in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they don't know how to handle.

Instead, either throw a more derived type that already exists in the framework, or create your own type that derives from Exception.

Throw specific exceptions

The following table shows which exception to throw for various types of invalid arguments, including the value parameter in the set accessor of a property.

The following table shows which exception to throw for various types of invalid operations.

For all other situations, consider creating your own type that derives from Exception and throw that.

How to fix violations

To fix a violation of this rule, change the type of the thrown exception to a specific type that's not one of the reserved types.

When to suppress warnings

Do not suppress a warning from this rule.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4