A colleague discovered wired debugger behavior in his VB.net solution. I admit that this will be more of an academic question, since it only affects the sequence of statements highlighted during debugging, and not the general behavior of the code. So everyone is curious:
We divided this into the following minimal console application:
Private Sub PlayWithExceptions
Dim a = 2
Try
throw new Exception("1")
Catch ex As Exception
If a = 2 Then
Dim x = New XElement("Dummy")
Else
throw
End If
End Try
End Sub
Sub Main()
Try
PlayWithExceptions()
Catch ex As Exception
End Try
End Sub
As you can see, the debugger throws an Exception ("1"), and the debugger goes into the catch clause of the PlayWithExceptions method. There, as "a" is always 2, the debugger goes to some dummy code (New XElement ...), from there to "End If" and, finally, back to the Else-list in the throw statement , I admit that Visual Studio does not throw an exception, but, nevertheless, it looks very strange.
" a = 2" "If True" .
.
Private Sub PlayWithExceptions
Dim a = 2
Try
throw new Exception("1")
Catch ex As Exception When a = 2
Dim x = New XElement("Dummy")
Catch ex As Exception
throw
End Try
End sub
# .
private static void PlayWithExceptions()
{
var a = 2;
try
{
throw new Exception("1");
}
catch (Exception)
{
if (a == 2)
{
var x = new XElement("Dummy");
}
else
{
throw;
}
}
}
static void Main(string[] args)
{
try
{
PlayWithExceptions();
}
catch (Exception ex)
{
}
}
.Net3.5 .Net4.6, AnyCPU x86 - VB-. Debug . VS2015 3.
- , Visual Studio VB ( )? ...