RosettaCodeData/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Visual-Basic-.NET/exceptions-catch-an-exception-thrown-in-a-nested-call-1.vb
2023-07-01 13:44:08 -04:00

37 lines
679 B
VB.net

Class U0
Inherits Exception
End Class
Class U1
Inherits Exception
End Class
Module Program
Sub Main()
Foo()
End Sub
Sub Foo()
Try
Bar()
Bar()
Catch ex As U0
Console.WriteLine(ex.GetType.Name & " caught.")
End Try
End Sub
Sub Bar()
Baz()
End Sub
Sub Baz()
' Static local variable is persisted between calls of the method and is initialized only once.
Static firstCall As Boolean = True
If firstCall Then
firstCall = False
Throw New U0()
Else
Throw New U1()
End If
End Sub
End Module