All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.vbnet.S2166.html Maven / Gradle / Ivy

There is a newer version: 10.5.0.109200
Show newest version

Why is this an issue?

Clear, communicative naming is important in code. It helps maintainers and API users understand the intentions for and uses of a unit of code. Using "exception" in the name of a class that does not extend Exception or one of its subclasses is a clear violation of the expectation that a class' name will indicate what it is and/or does.

Noncompliant code example

Public Class FruitException ' Noncompliant - this has nothing to do with Exception
    Private expected As Fruit
    Private unusualCharacteristics As String
    Private appropriateForCommercialExploitation As Boolean
    ' ...
End Class

Public Class CarException ' Noncompliant - does not derive from any Exception-based class
    Public Sub New(message As String, inner As Exception)
        ' ...
    End Sub
End Class

Compliant solution

Public Class FruitSport ' Compliant - class name does not end with 'Exception'
    Private expected As Fruit
    Private unusualCharacteristics As String
    Private appropriateForCommercialExploitation As Boolean
    ' ...
End Class

Public Class CarException Inherits Exception ' Compliant - correctly extends System.Exception
    Public Sub New(message As String, inner As Exception)
        MyBase.New(message, inner)
        ' ...
    End Sub
End Class




© 2015 - 2025 Weber Informatics LLC | Privacy Policy