12
private static ext.clsPassageiro ConversaoPassageiro(ncl.clsPassageiro clsPassageiro)
{
     ext.clsPassageiro _result = new ext.clsPassageiro();
     throw new NotImplementedException();
     return _result;
}

shows "unreachable code detected" for the return _result;,

private static ext.clsPassageiro ConversaoPassageiro(ncl.clsPassageiro clsPassageiro)
{
    ext.clsPassageiro _result = new ext.clsPassageiro();
    return _result;
    throw new NotImplementedException();
}

does not show "unreachable code detected" for the throw new NotImplementedException();,

Why does the second case not show the warning?

Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
Fábio Luiz
  • 438
  • 2
  • 11
  • 6
    Exceptions are meant for errors, and not program control flow. I think the compiler knows this, and doesn't see exceptions as a loss of program logic. Compiler warnings are really just a feature of a given compiler. – James Apr 26 '13 at 14:35
  • @James This must be answer. – Farhad Jabiyev Apr 26 '13 at 14:39
  • Good question... very interested to know if there is a good answer! (No help from msdn - http://msdn.microsoft.com/en-us/library/c0h4st1x%28v=vs.90%29.aspx) – Stuart Apr 26 '13 at 14:40
  • Exceptions show faults. When you reach code past a `return` statement, there's certainly something wrong. If you think about it that way, the fact that this warning doesn't come up is probably intentional. – Lee White Apr 26 '13 at 14:43
  • interestingly, Resharper marks it as `unreachable` for both methods. – default Apr 26 '13 at 14:44
  • 1
    @Default but there is still no warning in the errors list for the 2nd case (I tested it too) – Scott Chamberlain Apr 26 '13 at 14:44
  • 9
    This probably explains it: http://stackoverflow.com/questions/6371564/why-does-throwing-2-exceptions-in-a-row-not-generate-an-unreachable-code-warning?rq=1 – hometoast Apr 26 '13 at 14:45
  • I would vote for the compiler bug. – ken2k Apr 26 '13 at 14:46

0 Answers0