René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

on error [VBA]

option explicit

public sub on_error()
  call on_error_1()
  call on_error_2()
end sub


private sub on_error_1()

  on error goto some_label

    dim i, j, k as integer

    j = 5
    k = 0

    i = j/k  'Force division by zero...

    msgBox("on_error_1: never reached")

    exit sub

  some_label:

    msgBox("Error caught: " & err.number & vbCrLf & err.description)

end sub

private sub on_error_2()

  on error goto some_label

    dim i, j, k as integer

    j = 5
    k = 0

    i = j/k  'Force division by zero...

    msgBox("on_error_2: this is reached")

    exit sub

  some_label:

    msgBox("Error caught: " & err.number & vbCrLf & err.description)

    resume next

end sub
See also other VBA stuff