54 lines
1.2 KiB
Plaintext
54 lines
1.2 KiB
Plaintext
It is expected that some methods should be called with caution, but others, such as `ToString`, are expected to "just work". Throwing an exception from such a method is likely to break callers' code unexpectedly.
|
|
|
|
An issue is raised when an exception is thrown from any of the following:
|
|
|
|
* Event accessors
|
|
* `Object.Equals`
|
|
* `IEquatable.Equals`
|
|
* `GetHashCode`
|
|
* `ToString`
|
|
* `static` constructors
|
|
* Module initializers
|
|
* `IDisposable.Dispose`
|
|
* operators ``++==, !=, <, >, <=, >=++``
|
|
* `implicit` cast operators
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,csharp]
|
|
----
|
|
public override string ToString()
|
|
{
|
|
if (string.IsNullOrEmpty(Name))
|
|
{
|
|
throw new ArgumentException("..."); // Noncompliant
|
|
}
|
|
//...
|
|
----
|
|
|
|
|
|
== Exceptions
|
|
|
|
`System.NotImplementedException` and its derivatives are ignored.
|
|
|
|
`System.InvalidOperationException`, `System.NotSupportedException`, and `System.ArgumentException` and their derivatives are ignored in event accessors.
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
include::highlighting.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|