All rules
CA1064Design Enabled by default: No

Exceptions should be public

Exceptions should be public

Microsoft docs

Description

An internal exception is only visible inside its own internal scope. After the exception falls outside the internal scope, only the base exception can be used to catch the exception. If the internal exception is inherited from System.Exception, System.SystemException, or System.ApplicationException, the external code will not have sufficient information to know what to do with the exception.

But, if the code has a public exception that later is used as the base for an internal exception, it is reasonable to assume the code further out will be able to do something intelligent with the base exception. The public exception will have more information than what is provided by System.Exception, System.SystemException, or System.ApplicationException.

Cause

A non-public exception derives directly from System.Exception, System.SystemException, or System.ApplicationException.

How to fix violations

Make the exception public, or derive the internal exception from a public exception that is not System.Exception, System.SystemException, or System.ApplicationException.

Example

#pragma warning disable CA1064
// The code that's violating the rule is on this line.
#pragma warning restore CA1064

When to suppress

Suppress a message from this rule if you are sure in all cases that the private exception will be caught within its own internal scope.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0