我是Visual Basic的新手,嘗試執行try和catch塊的下面的代碼。我只是檢查一下,我們是否可以在VB.net中同時捕獲多個異常。但我只得到一條消息。請清楚地解釋我。我們可以在VB.net中同時捕獲多個異常嗎?
的代碼是在這裏下
Public Class tempIsZeroException : Inherits System.Exception
Public Sub New(ByVal mesage As String)
MyBase.New(mesage)
End Sub
End Class
Module Module1
Sub Main()
Dim a As Integer
Dim b As Integer
Console.WriteLine("ENter any number")
a = Console.ReadLine()
Console.WriteLine("ENter any number")
b = Console.ReadLine()
Try
If a = 0 Then
Throw New ApplicationException("asdf")
End If
If b = 0 Then
Throw New tempIsZeroException("Exception caught")
End If
Catch ex As TempIsZeroException
Console.WriteLine(ex.Message())
Catch ex1 As ApplicationException
Console.WriteLine(ex1.Message())
End Try
Console.ReadLine()
End Sub
End Module
當你拋出一個異常時,代碼跳轉到相關的catch塊,執行catch塊中存在的任何代碼,然後在End Try外面跳轉。目前還不清楚你會從這段代碼中得到什麼結果...... – Steve