Example - On Error Statement

  1. Sub Main

    1. On Error GoTo dude

      Dim x as object

      x.draw' Object not set

      jpe' Undefined function call

      print 1/0' Division by zero

      Err.Raise 6          ' Generate an "Overflow" error

      MsgBox "Back"

      MsgBox "Jack"

      Exit Sub

      dude:

      MsgBox "HELLO"

      Print Err.Number, Err.Description

      Resume Next

      MsgBox "Should not get here!"

      MsgBox "What?"

    End Sub

Errors can be raised with the syntax:

  1. Err.Raise x