Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca2201.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ helpviewer_keywords:
- DoNotRaiseReservedExceptionTypes
author: gewarren
ms.author: gewarren
dev_langs:
- CSharp
---
# CA2201: Do not raise reserved exception types

Expand Down Expand Up @@ -78,6 +80,29 @@ For all other situations, consider creating your own type that derives from <xre

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.

## Example

```csharp
// This code violates the rule.
throw new Exception();
throw new NullReferenceException();
throw new IndexOutOfRangeException();
// ...

// This code satisfies the rule.
throw new ArgumentException();
throw new ArgumentNullException();
throw new InvalidOperationException();
// ...

// A minimal implementation of inheritance from Exception
public class CustomException : Exception { }

// Or create your own type that derives from Exception
// This code satisfies the rule too.
throw new CustomException();
```

## When to suppress warnings

Do not suppress a warning from this rule.
Expand Down