Exception
s 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
.
if (x < 0)
{
new ArgumentException(nameof(x));
}
if (x < 0)
{
throw new ArgumentException(nameof(x));
}