Bug in Dead Code Detection?
I have found a possible issue with the dead code detection. Given the following code:
<code>
using(var connection = new SqlConnection(connectionString))
{
connection.Open();
using(var transaction = connection.BeginTransaction())
{
SqlHelper.ExecuteNonQuery(transaction, procedureName, parameters);
transaction.Commit;
return true;
}
}
return false;
</code>
the final line is marked as unreachable - which is false. If any exceptions happen inside of either <c>using</c> expression, then the last line will be reached. Only in the case where no exceptions happen is it unreachable.
Please sign in to leave a comment.
Hello David,
The code sample
is actually transformed by the compiler into
According to C# Language Specification the try/finally block re-throws the
exception after executing the 'finally' block, so the execution will never
reach the last return statement. Thank you!
Andrey Serebryansky
Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"