Try and catch Exception: InvalidCastException : Catch Exception « Language Basics « VB.Net






Try and catch Exception: InvalidCastException

Imports System
Imports System.Diagnostics

Public Class MainClass

    Shared Sub Main()

        Try
            Dim i As Integer = CInt("bad value")
        Catch ex As InvalidCastException
            Dim txt As String = "InvalidCastException"
            MsgBox(txt)
        Catch ex As Exception
            Dim txt As String = "Exception"
            MsgBox(txt)
        End Try
    End Sub
End Class


           
       








Related examples in the same category

1.Catch Exception DemoCatch Exception Demo
2.Catch All Unhandled ExceptionsCatch All Unhandled Exceptions