<< Prev        Next >>

ID : 109

On Error

Function

To specify the processing routine at the time of error level 1 occurrence.

Syntax

On Error processing

Guaranteed entry

Processing
Designate the processing at the time of error occurrence. "Resume Next" or "GoTo label name," and "Goto 0" are designated.

Description

Error processing proceeds without stopping the program when an Error level 1 occurs in the statement after execution of this statement.

Error processing is disabled by On Error GoTo 0.

Error processing designation is only valid within the procedure.

Processing designation Error processing description
Resume Next The statement where the error occurs is not executed and the following lines are executed.
GoTo label name Designate an error processing routine label name.
GoTo 0 Disable the error processing.

Attention

  • Error processing designation is only valid within the procedure. "Refer to "Example Error Processing."
  • Level 1 or Level 2 errors which occurred within the Supervisory Task or TP Panel tasks are processed as error level 3. However, when writing On Error command within the Supervisory Task or TP Panel tasks, these errors are treated as Level 1 so as to execute On Error command as intended.

Example

'!TITLE "Executing Label Processing Designated When Error Occurred"
' Display a warning statement when an error occurs
Sub Sample_OnErrorGoTo

  Dim aaa As Integer
  
  'Error processing routing is LABEL1
  On Error GoTo LABEL1 
  
  aaa = "test"  ' Error occurred due to this processing

  ' If any error occurs, the system skips to the next line without executing the pertinent line
  On Error Resume Next 

  aaa = "test"  ' Error occurred due to this processing

  ' Error processing routine disabled (Error occurs)
  On Error GoTo 0 

  aaa = "test"  ' Error occurred due to this processing
  
  Exit Sub

LABEL1:

  ' Display a warning statement on the message output window
  PrintDbg "Error Occurred !!"
  Resume Next

End Sub

ID : 109

<< Prev        Next >>