2

Visual Studio 2010 marks, underlines the statement in green, the return in the else clause as unreachable which is logical.

public void UnreachableElse()
    {
        if (true) //If true will always evaluate to true.
            return;
        else //unreachable.
            return; 
    }

However consider the following.

public void UnreachableElse()
    {
        if (true) //If true will always evaluate to true.
            return;
        else //unreachable.
            throw new Exception();     
    }

Why isn't any of the throw statement marked, underlined, as unreachable?

Synergyze
  • 23
  • 3
  • What exactly do you mean by "marks"? Does it give an error? – Jon Skeet Jun 20 '13 at 11:27
  • Visual Studio underlines the unreachable code in green and with full Code analysis enabled, it warns for the statement. However it doesn't do that in this case. – Synergyze Jun 20 '13 at 11:30
  • possible duplicate: http://stackoverflow.com/questions/6371564/why-does-throwing-2-exceptions-in-a-row-not-generate-an-unreachable-code-warning – Nikita B Jun 20 '13 at 11:38
  • Thank you, Nik. Thought I had searched extensively enough. – Synergyze Jun 20 '13 at 11:50

0 Answers0