Why is this an issue?
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");
}
// ...
}
Resources