Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3871

Exception types should be "public"

    XMLWordPrintable

    Details

    • Message:
      Make this class "public".
    • Highlighting:
      Hide

      visibility modifier

      Show
      visibility modifier
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      Java
    • Covered Languages:
      C#
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources, Test Sources
    • OWASP:
      A10
    • FxCop:
      ExceptionsShouldBePublic, CA1064

      Description

      The point of having custom exception types is to convey more information than is available in standard types. But custom exception types must be public for that to work.

      If a method throws a non-public exception, the best you can do on the caller's side is to catch the closest public base of the class. That is, you lose all that custom information you created the exception type to pass.

      Noncompliant Code Example

      internal class MyException : Exception   // Noncompliant
      {
        // ...
      }
      

      Compliant Solution

      public class MyException : Exception
      {
        // ...
      }
      

      Exceptions

      This rule ignores Exception types that are not derived directly from System.Exception, System.SystemException, or System.ApplicationException.

      See

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ann.campbell.2 Ann Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: