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

org.sonar.plugins.csharp.S4027.html Maven / Gradle / Ivy

There is a newer version: 10.2.0.105762
Show newest version

Why is this an issue?

Exceptions types should provide the following constructors:

  • public MyException()
  • public MyException(string)
  • public MyException(string, Exception)

The absence of these constructors can complicate exception handling and limit the information that can be provided when an exception is thrown.

How to fix it

Code examples

Noncompliant code example

public class MyException : Exception // Noncompliant: several constructors are missing
{
    public MyException()
    {
    }
}

Compliant solution

public class MyException : Exception
{
    public MyException()
    {
    }

    public MyException(string message)
        : base(message)
    {
    }

    public MyException(string message, Exception innerException)
        : base(message, innerException)
    {
    }
}

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy