虽然它似乎有效,但一方面,我会谨慎使用保留对象名称 (Err) 作为标签。
On Error GoTo ErrorHandler
' Your code here
' Make sure you don't hit the errorhandler when there's
' no error:
NormalExit:
Exit Sub ' or Function, whichever this is
ErrorHandler:
If err.Number = 123456788 Then
' Take corrective action
' then continue
Resume Next
End If
' Trap other specific or general errors here
' Then make sure you know where you're going to exit:
Resume NormalExit
如果您需要捕获可能仅在代码中某些位置发生的非常具体的错误,您还可以执行本地错误处理程序:
On Error Resume Next
' Some code that might cause problems
' Did it throw the error you're trying to trap?
If Err.Number = 12398745 then
' Corrective action
End If
' And now we return to our regularly scheduled error trapping
On Error GoTo ErrorHandler