38 lines
881 B
Plaintext
38 lines
881 B
Plaintext
Throwing such general exceptions as ``++Exception++``, ``++SystemException++``, ``++ApplicationException++``, ``++IndexOutOfRangeException++``, ``++NullReferenceException++``, ``++OutOfMemoryException++`` and ``++ExecutionEngineException++`` prevents calling methods from handling true, system-generated exceptions differently than application-generated errors.
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
public void DoSomething(object obj)
|
|
{
|
|
if (obj == null)
|
|
{
|
|
throw new NullReferenceException("obj"); // Noncompliant
|
|
}
|
|
// ...
|
|
}
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
public void DoSomething(object obj)
|
|
{
|
|
if (obj == null)
|
|
{
|
|
throw new ArgumentNullException("obj");
|
|
}
|
|
// ...
|
|
}
|
|
----
|
|
|
|
include::../see.adoc[]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|