0
我創建了一個名爲ZeroException的繼承的類,它繼承自System.DivideByZero Class,但是當發生分歧的異常時它不捕獲該事件。從system.dividebyzeroexception繼承的異常類
Class ZeroException
Inherits System.DivideByZero
Public Overrides ReadOnly Property Message() as String
Get
Return "Divide By Zero"
End Get
End Property
End Class
主要代碼:
Sub Calc()
dim x as integer=5
dim y as integer=0
dim k as single
Try
k=x\y 'Integer Division
Catch ex as ZeroException
Console.WriteLine(ex.Message) 'But I get another message. Not Divide By Zero
End Try
End Sub
你有這個倒退。你無法捕捉到更多派生的異常。 –