我有一个继承Exception的自定义异常类。 在我的Try-Catch块中,有一行代码会导致InvalidCastException。未捕获但未处理的自定义异常
但是,异常总是在导致它的代码行上未处理,并且未被Catch块捕获。
Public Class InvalidPremiumException
Inherits System.Exception
Public Sub New()
End Sub
Public Sub New(message As String)
MyBase.New(message)
End Sub
Public Sub New(message As String, inner As Exception)
MyBase.New(message, inner)
End Sub
End Class
然后在另一个类:
Try
' code that causes an InvalidCastException here
Catch ex As InvalidPremiumException
Console.WriteLine("Invalid or Missing Premium")
End Try
如果我的答案已经解决了您的问题,请将其标记为'答案' –