5.4.4.1 On Error Statement

An <on-error-statement> specifies a new error-handling policy for a VBA procedure.

 on-error-statement = "On" "Error" error-behavior  
  
 error-behavior = ("Resume" "Next") / ("GoTo" (statement-label / -1))  

Static Semantics

§ The containing procedure MUST contain exactly one <statement-label-definition> with the same <statement-label> as the <statement-label> contained in the <error-behavior> element, unless the <statement-label> is a <line-number-label> whose data value is the Integer 0.

 

Runtime Semantics.

§ An <on-error-statement> specifies a new error-handling policy for the current activation of the containing procedure.

§ The Err object (section 6.1.3.2) is reset.

§ If the <error-behavior> is "Resume Next", the error-handling policy is set to "Resume Next".

§ If the <error-behavior> has a <statement-label> that is a <line-number-label> whose data value is the Integer data value 0 then the error-handling policy disabled. If the <error-behavior> is any other <statement-label>, then the error-handling policy set to goto the <statement-label>.