C#

C#

Made by DeepSource

Exceptions that are created must be used CS-W1043

Bug risk
Major
Autofix

Exceptions are instantiated just like normal classes via the new keyword and then thrown using the throw keyword. However, in this case, the Exception that is being created is neither thrown nor used in any other manner. It is recommended that you either get rid of this statement completely or throw the Exception.

Bad Practice

if (x < 0)
{
    new ArgumentException(nameof(x));
}

Recommended

if (x < 0)
{
    throw new ArgumentException(nameof(x));
}