Resume
在错误处理例程完成后恢复执行。
语法:
Resume [ 0 ]
Resume Next
Resume line
- Resume
- 如果错误发生在与错误处理程序相同的过程中,执行从导致错误的语句恢复。如果错误发生在被调用过程中,执行从最后调用包含错误处理例程过程的语句恢复。Resume和Resume 0等效。
- Resume Next
- 如果错误发生在与错误处理程序相同的过程中,执行从导致错误的语句之后紧接着的语句恢复。如果错误发生在被调用过程中,执行从最后调用包含错误处理例程过程(或On Error Resume Next语句)的语句之后紧接着的语句恢复。
- Resume line
- 执行在指定的line处恢复。line参数是行标签或行号,必须与错误处理程序在同一过程中。
在错误处理例程以外的任何地方使用Resume语句会引发错误。
示例
本示例使用Resume语句结束过程中的错误处理,然后从导致错误的语句恢复执行。错误号55用于演示Resume语句的使用。
vb
Sub ResumeStatementDemo()
On Error GoTo ErrorHandler ' Enable error-handling routine.
Open "TESTFILE" For Output As #1 ' Open file for output.
Kill "TESTFILE" ' Attempt to delete open file.
Exit Sub ' Exit Sub to avoid error handler.
ErrorHandler: ' Error-handling routine.
Select Case Err.Number ' Evaluate error number.
Case 55 ' "File already open" error.
Close #1 ' Close open file.
Case Else
' Handle other situations here....
End Select
Resume ' Resume execution at same line that caused the error.
End Sub