org.sonar.plugins.csharp.S3877.html Maven / Gradle / Ivy
Why is this an issue?
The rule is reporting when an exception is thrown from certain methods and constructors. These methods are expected to behave in a specific way and
throwing an exception from them can lead to unexpected behavior and break the calling code.
public override string ToString()
{
if (string.IsNullOrEmpty(Name))
{
throw new ArgumentException(nameof(Name)); // Noncompliant
}
//...
}
An issue is raised when an exception is thrown from any of the following:
- ToString
- Object.Equals
- IEquatable.Equals
- GetHashCode
- IDisposable.Dispose
- Event accessors
- static constructors
- Module initializers
- https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/operator-overloading
- implicit cast
operators
Exceptions
Certain exceptions will be ignored in specific contexts, thus not raising the issue:
-
System.NotImplementedException
and its derivatives are ignored for all the aforementioned.
-
System.InvalidOperationException
, System.NotSupportedException
, and System.ArgumentException
and their
derivatives are ignored in event accessors.
Resources
Documentation
© 2015 - 2024 Weber Informatics LLC | Privacy Policy