Exception classes should be declared as public

Rule ND1810 Visibility

Custom exception classes offer finer details than standard exceptions, but catching code must have access to the exception class to use them.

How to fix

Declare custom exception classes public, catchable in every context.

CQLinq source

This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.

// <Name>Exception classes should be declared as public</Name>
// <Id>ND1810:ExceptionClassesShouldBeDeclaredAsPublic</Id>

warnif count > 0 
from t in JustMyCode.Types
where  t.IsExceptionClass && 
      !t.IsNested && 
      !t.IsPublic

select new { 
  t, 
  Debt = 2.ToMinutes().ToDebt(),
  Severity = Severity.Medium
}

//<Expl>
// The exception {0} should be declared as public.
//</Expl>

//<Desc>
// Custom exception classes offer finer details than standard exceptions,
// but catching code must have access to the exception class to use them.
//</Desc>

//<HowToFix>
// Declare custom exception classes public, catchable in every context.
//</HowToFix>

Visibility: all 12 items