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

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:

You can look at examples of errors detected by the V3006 diagnostic.


Bugs Found

Checked Projects
414
Collected Errors
14 218
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site. Learn More →
Accept