Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
>
>
>
V5602. OWASP. The object was created...
menu mobile close menu
Additional information
toggle menu Contents

V5602. OWASP. The object was created but it is not being used. The 'throw' keyword could be missing.

09 Fév 2021

The analyzer has detected a potential error when an instance of a class derived from 'System.Exception' is created but not being used in any way.

Here's an example of incorrect code:

public void DoSomething(int index)
{
  if (index < 0)
    new ArgumentOutOfRangeException(); 
  else
  ....
}

In this fragment, the 'throw' statement is missing, so executing this code will only result in creating an instance of a class derived from 'System.Exception' without it being used in any way, and the exception won't be generated. The correct version of this code should look something like this:

public void DoSomething(int index)
{
  if (index < 0)
    throw new ArgumentOutOfRangeException(); 
  else
  ....
}

This diagnostic is classified as: