← back to index

S3984 — Exceptions should not be created without being thrown

Language: C#  |  Type: BUG  |  Severity: Major

Tags: error-handling

Why is this an issue?

Creating a new Exception without actually throwing does not achieve the intended purpose.

if (x < 0)
{
    new ArgumentException("x must be nonnegative");
}

Ensure to throw the Exception with a throw statement.

if (x < 0)
{
    throw new ArgumentException("x must be nonnegative");
}

Resources

Documentation