「VB.net」try catch構文で例外処理をする

2020年10月27日

構文

Try
    [ tryStatements ]
    [ Exit Try ]
[ Catch [ exception [ As type ] ] [ When expression ]
    [ catchStatements ]
    [ Exit Try ] ]
[ Catch ... ]
[ Finally
    [ finallyStatements ] ]
End Try

サンプルコード

Module ModuleTest
    Sub Main()
        Dim cftA As Integer = 12
        Dim cftB As Integer = 0

        Try
            Dim ans As Integer = testFunc(cftA, cftB)
        Catch ex As ArithmeticException
            Console.WriteLine(ex.Message)
        Finally
            Console.WriteLine("aaa")
        End Try

    End Sub

    Private Function testFunc(cftA As Integer, cftB As Integer)
        Return cftA / cftB
    End Function
End Module

 

VB.net

Posted by arkgame