D
Don
I have discovered a bug in the Current Statement highlighting in the VB.NET
IDE that occurs under a specific set of circumstances. This is the specific
set of circumstances :
- You have a Try..Catch..Finally or Try..Finally block in your code
- The Finally section has one or more single-line IF..THEN or IF..THEN..ELSE
statements
The problem occurs with the last IF..THEN (or IF..THEN..ELSE) line in the
Finally section as follows:
1. With an IF..THEN statement, if the condition is False, the Current
Statement will continue on to the True branch and appear as though it is
executing it, but it is not.
2. With an IF..THEN..ELSE statement, if the condition is True, the Current
Statement will go the the True branch, then continue on to the False branch
and appear as though it is executing it as well. In reality, only the code
for the True branch is executed.
Here is some example code that will illustrate the problem. Put a breakpoint
on the first line of code and watch the magic:
Example 1.
Try
Finally
If False Then Console.WriteLine("1true") ' Works fine
If False Then Console.WriteLine("2true") ' Works fine
If False Then Console.WriteLine("3true") ' Works fine
If False Then Console.WriteLine("4true") ' Whoops...
End Try
Example 2.
Try
Finally
If True Then Console.WriteLine("1true") Else Console.WriteLine("1false")
' Works fine
If True Then Console.WriteLine("2true") Else Console.WriteLine("2false")
' Works fine
If True Then Console.WriteLine("3true") Else Console.WriteLine("3false")
' Works fine
If True Then Console.WriteLine("4true") Else Console.WriteLine("4false")
' Whoops...
End Try
As far as I can tell, the bug is simply cosmetic: even though it shows it's
executing the wrong branch, it really isn't.
- Don
IDE that occurs under a specific set of circumstances. This is the specific
set of circumstances :
- You have a Try..Catch..Finally or Try..Finally block in your code
- The Finally section has one or more single-line IF..THEN or IF..THEN..ELSE
statements
The problem occurs with the last IF..THEN (or IF..THEN..ELSE) line in the
Finally section as follows:
1. With an IF..THEN statement, if the condition is False, the Current
Statement will continue on to the True branch and appear as though it is
executing it, but it is not.
2. With an IF..THEN..ELSE statement, if the condition is True, the Current
Statement will go the the True branch, then continue on to the False branch
and appear as though it is executing it as well. In reality, only the code
for the True branch is executed.
Here is some example code that will illustrate the problem. Put a breakpoint
on the first line of code and watch the magic:
Example 1.
Try
Finally
If False Then Console.WriteLine("1true") ' Works fine
If False Then Console.WriteLine("2true") ' Works fine
If False Then Console.WriteLine("3true") ' Works fine
If False Then Console.WriteLine("4true") ' Whoops...
End Try
Example 2.
Try
Finally
If True Then Console.WriteLine("1true") Else Console.WriteLine("1false")
' Works fine
If True Then Console.WriteLine("2true") Else Console.WriteLine("2false")
' Works fine
If True Then Console.WriteLine("3true") Else Console.WriteLine("3false")
' Works fine
If True Then Console.WriteLine("4true") Else Console.WriteLine("4false")
' Whoops...
End Try
As far as I can tell, the bug is simply cosmetic: even though it shows it's
executing the wrong branch, it really isn't.
- Don