Skip to content

Commit b400528

Browse files
authored
Merge pull request #2079 from MicrosoftDocs/master
5/22 AM Publish
2 parents 1466ac0 + 7f14cd7 commit b400528

File tree

45 files changed

+487
-577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+487
-577
lines changed

.openpublishing.redirection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,11 @@
690690
"redirect_url": "/visualstudio/debugger/error-the-microsoft-visual-studio-remote-debugging-monitor-no-permission",
691691
"redirect_document_id": false
692692
},
693+
{
694+
"source_path": "docs/debugger/how-to-debug-with-code-center-premium-source.md",
695+
"redirect_url": "/visualstudio/debugger/index",
696+
"redirect_document_id": false
697+
},
693698
{
694699
"source_path": "docs/deployment/installshield-limited-edition.md",
695700
"redirect_url": "/visualstudio/deployment/deploying-applications-services-and-components",

docs/code-quality/ca1032-implement-standard-exception-constructors.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ms.workload:
1818
- "multiple"
1919
---
2020
# CA1032: Implement standard exception constructors
21+
2122
|||
2223
|-|-|
2324
|TypeName|ImplementStandardExceptionConstructors|
@@ -26,28 +27,41 @@ ms.workload:
2627
|Breaking Change|Non-breaking|
2728

2829
## Cause
29-
A type extends <xref:System.Exception?displayProperty=fullName> and does not declare all the required constructors.
3030

31-
## Rule Description
32-
Exception types must implement the following constructors:
31+
A type extends <xref:System.Exception?displayProperty=fullName> but doesn't declare all the required constructors.
32+
33+
## Rule description
34+
35+
Exception types must implement the following three constructors:
36+
37+
- public NewException()
38+
39+
- public NewException(string)
3340

34-
- public NewException()
41+
- public NewException(string, Exception)
3542

36-
- public NewException(string)
43+
Additionally, if you're running legacy FxCop static code analysis as opposed to [Roslyn-based FxCop analyzers](../code-quality/roslyn-analyzers-overview.md), the absence of a fourth constructor also generates a violation:
3744

38-
- public NewException(string, Exception)
45+
- protected or private NewException(SerializationInfo, StreamingContext)
3946

40-
- protected or private NewException(SerializationInfo, StreamingContext)
47+
Failure to provide the full set of constructors can make it difficult to correctly handle exceptions. For example, the constructor that has the signature `NewException(string, Exception)` is used to create exceptions that are caused by other exceptions. Without this constructor, you can't create and throw an instance of your custom exception that contains an inner (nested) exception, which is what managed code should do in such a situation.
4148

42-
Failure to provide the full set of constructors can make it difficult to correctly handle exceptions. For example, the constructor that has the signature `NewException(string, Exception)` is used to create exceptions that are caused by other exceptions. Without this constructor you cannot create and throw an instance of your custom exception that contains an inner (nested) exception, which is what managed code should do in such a situation. The first three exception constructors are public by convention. The fourth constructor is protected in unsealed classes, and private in sealed classes. For more information, see [CA2229: Implement serialization constructors](../code-quality/ca2229-implement-serialization-constructors.md)
49+
The first three exception constructors are public by convention. The fourth constructor is protected in unsealed classes, and private in sealed classes. For more information, see [CA2229: Implement serialization constructors](../code-quality/ca2229-implement-serialization-constructors.md)
4350

44-
## How to Fix Violations
45-
To fix a violation of this rule, add the missing constructors to the exception, and make sure that they have the correct accessibility.
51+
## How to fix violations
4652

47-
## When to Suppress Warnings
48-
It is safe to suppress a warning from this rule when the violation is caused by using a different access level for the public constructors.
53+
To fix a violation of this rule, add the missing constructors to the exception, and make sure that they have the correct accessibility.
54+
55+
## When to suppress warnings
56+
57+
It's safe to suppress a warning from this rule when the violation is caused by using a different access level for the public constructors. Additionally, it's okay to suppress the warning for the `NewException(SerializationInfo, StreamingContext)` constructor if you're building a Portable Class Library (PCL).
4958

5059
## Example
51-
The following example contains an exception type that violates this rule and an exception type that is correctly implemented.
5260

53-
[!code-csharp[FxCop.Design.ExceptionMultipleCtors#1](../code-quality/codesnippet/CSharp/ca1032-implement-standard-exception-constructors_1.cs)]
61+
The following example contains an exception type that violates this rule and an exception type that is correctly implemented.
62+
63+
[!code-csharp[FxCop.Design.ExceptionMultipleCtors#1](../code-quality/codesnippet/CSharp/ca1032-implement-standard-exception-constructors_1.cs)]
64+
65+
## See also
66+
67+
[CA2229: Implement serialization constructors](../code-quality/ca2229-implement-serialization-constructors.md)

0 commit comments

Comments
 (0)