我定义了2个自定义异常,如下所示
Public Class SkipException
Inherits System.ApplicationException
End Class
Public Class NoRecordFoundException
Inherits System.ApplicationException
End Class
在我的代码中,场景是1.数据导致一般异常2.我没有数据3.我已经处理过的异常
Try
'Some code here
Try
''Do some code
''Cant find the record
If i = 0 then
Throw NoRecordFoundException
End if
Catch ex as Exception
End Try
Try
''Cant do nothing so just skip
If CantDoNothing then
Throw SkipException
End if
Catch ex as Exception
End Try
Catch SkipException
''Some code here
Catch NoRecordFoundException
'' some code here
Catch ex as Exception
''Handle regular exception
End Try
那么这会奏效吗?异常会转到外部处理而不是内部捕获吗?
现在,我正在重新抛出异常以使其正常工作。
发布于 2019-10-18 18:58:02
只需处理特定的异常并重新抛出。下面的Catch ex as Exception
将忽略在它之前捕获的异常。
Try
Try
Throw New NoRecordFoundException()
Catch ex As NoRecordFoundException
Throw
Catch ex As Exception
' nothing happens here
End Try
Catch ex As NoRecordFoundException
' handled here
Catch ex As Exception
' nothing happens here
End Try
https://stackoverflow.com/questions/58455846
复制相似问题