LOTUSSCRIPT 言語
以下に例を示します。
Sub TestHand Dim num As Single num!= 1 Print num!/ 0 End Sub Sub SuperHand On Error Resume Next Call TestHand() ' When control returns to SuperHand upon an error ' in TestHand, execution continues at this Print statement. Print "Continuing after calling sub TestHand." Exit Sub End Sub Call SuperHand() ' Output: ' Continuing after calling sub TestHand.
同様に、ステートメント Resume Next が下位レベルのプロシージャの中で発生したエラーの処理ルーチン内に入れられていると、Resume Next が指定する「次のステートメント」は呼び出し元プロシージャの次のステートメントを指します。
エラー処理ルーチン内のステートメント Resume 0 (または単に Resume) は、エラーが発生した行 (その行が下位レベルのプロシージャにある場合でも) を再実行することを意味します。
' The sub SuperHand calls the sub TestHand with an argument ' of 0, which produces an error.The error is handled by an ' error-handling routine in the caller, the sub SuperHand. ' Handling the error includes resetting the call argument ' to 1, and then calling TestHand with this argument.On the ' second call no error occurs. Sub TestHand(num As Integer) Dim num2 As Single If num <> 0 GoTo ProcPo Print "Call argument to sub" & _ "TestHand is 0; will generate error." ' There's no error-handling routine in sub TestHand for ' division-by-zero, so control returns to the calling sub ' SuperHand when the next statement is executed. num2!= num% / 0 ' This Print statement is not executed at all. Print "Continue here after division-by-zero error?" Exit Sub ' Come here if call argument is nonzero. ProcPos: Print "Call argument to sub TestHand is nonzero" & _ " (no error)." Exit Sub End Sub Sub SuperHand Dim numIn As Integer ' A division-by-zero error not handled in sub TestHand ' is handled by the error-handling routine at DivZero. On Error GoTo DivZero Call TestHand(numIn%) Exit Sub DivZero: Print "Handling division-by-zero error." numIn% = 1 ' Re-execute the statement that caused the error ' being handled.This will be the statement Call ' TestHand(numIn%) above.The call argument is now 1. Resume 0 End Sub Call SuperHand() ' Output: ' Call argument to sub TestHand is 0; will generate error. ' Handling division-by-zero error. ' Call argument to sub TestHand is nonzero (no error).
関連項目