当发生错误时,我想抛出大约 20 条可能的异常消息。捕捉异常时我需要这样的东西
Try
' do domthing
Catch ex As CustomInvalidArgumentException
'do domthing
Catch ex As CustomUnexcpectedException
'do domthing
Catch ex As Exception
'do domthing
End Try
目前我有这样的课
<Serializable()> _
Public Class CustomException
Inherits Exception
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal message As String)
MyBase.New(message)
End Sub
Public Sub New(ByVal format As String, ByVal ParamArray args As Object())
MyBase.New(String.Format(format, args))
End Sub
Public Sub New(ByVal message As String, ByVal innerException As Exception)
MyBase.New(message, innerException)
End Sub
Public Sub New(ByVal format As String, ByVal innerException As Exception, ByVal ParamArray args As Object())
MyBase.New(String.Format(format, args), innerException)
End Sub
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)
End Sub
End Class
我是否必须为每种类型的异常创建一个从 Exception 继承的类