共用方式為


Resume 陳述式

在完成錯誤處理常式之後繼續執行。

我們建議您使用結構化的例外處理,可能的話,程式碼中,而不是使用非結構化的例外處理和On Error和Resume陳述式。 如需詳細資訊,請參閱 Try...Catch...Finally 陳述式 (Visual Basic)

Resume [ Next | line ]

組件

  • Resume
    必要項。 如果錯誤發生在與錯誤處理常式相同的程序中,則繼續執行導致錯誤的陳述式。 如果錯誤發生在呼叫的程序中,則從包含錯誤處理常式的程序中最後呼叫的陳述式繼續執行。

  • Next
    選擇項。 如果錯誤發生在與錯誤處理常式相同的程序中,則繼續執行導致錯誤發生的陳述式後面的陳述式。 如果錯誤發生在呼叫的程序中,則從包含錯誤處理常式 (或 On Error Resume Next 陳述式) 的程序中最後呼叫的陳述式後面的陳述式繼續執行。

  • line
    選擇項。 從必要的 line 引數中所指定的那一行繼續執行。 line 引數就是行標籤或行號,且必須位在與錯誤處理常式相同的程序中。

備註

注意事項注意事項

我們建議您使用結構化的例外處理,可能的話,程式碼中,而不是使用非結構化的例外處理和On Error和Resume陳述式。如需詳細資訊,請參閱 Try...Catch...Finally 陳述式 (Visual Basic)

如果您在錯誤處理常式以外的位置使用 Resume 陳述式,將會發生錯誤。

Resume 陳述式無法在含有 Try...Catch...Finally 陳述式的任何程序中使用。

範例

這個範例會使用 Resume 陳述式結束程序中的錯誤處理,然後繼續執行造成錯誤的陳述式。 產生錯誤代碼 55,說明如何使用 Resume 陳述式。

Sub ResumeStatementDemo()
  On Error GoTo ErrorHandler   ' Enable error-handling routine.
  Dim x As Integer = 32
  Dim y As Integer = 0
  Dim z As Integer
  z = x / y   ' Creates a divide by zero error
  Exit Sub   ' Exit Sub to avoid error handler.
ErrorHandler:     ' Error-handling routine.
  Select Case Err.Number   ' Evaluate error number.
      Case 6   ' "Divide by zero" error.
        y = 1 ' Sets the value of y to 1 and tries the calculation again.
      Case Else
        ' Handle other situations here....
  End Select
  Resume   ' Resume execution at same line
  ' that caused the error.
End Sub

需求

命名空間Microsoft.VisualBasic

組件:Visual Basic 執行階段程式庫 (在 Microsoft.VisualBasic.dll 中)

請參閱

參考

Try...Catch...Finally 陳述式 (Visual Basic)

Error 陳述式

On Error 陳述式 (Visual Basic)