Mega Code Archive

 
Categories / VB.Net Tutorial / Language Basics
 

Variable scope in try catch statement

public class Test    public Shared Sub Main         Try             Dim i As Integer = CInt("bad value")         Catch ex As InvalidCastException             Dim txt As String = "InvalidCastException"             Console.WriteLine(txt)         Catch ex As Exception             Dim txt As String = "Exception"             Console.WriteLine(txt)         End Try    End Sub End class InvalidCastException