Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

I am running into a situation in someone else’s code where an Err.Raise call is not getting handled by any of the upstream calling functions and ends up calling the main VBA system debugger displaying the VBA error dialog.

I was trying to recreate the problem but so far I haven’t been able to.

Here’s my code attempting to create 3 levels of errors with various handled and unhandled errors to see what results I get:

Sub MainProcedure()
    On Error GoTo MainErrorHandler
    Call NestedProcedure
    Err.Raise 100, , "Handled Error in MainProcedure"
    Exit Sub
MainErrorHandler:
    MsgBox "Error in MainProcedure: " & Err.Number & " " & Err.Description
    Resume Next
End Sub

Sub NestedProcedure()
    ' Code here will bubble up to the Main Procedure that called it, 
    ' but doesn't return to execute additional code
    'Err.Raise 200, , "Unhandled in NestedProcedure"
    NestedNestedProcedure
    On Error GoTo NestedErrorHandler
    ' Code erroring here will be handled only by the NestedErrorHandler
    Err.Raise 300, , "Handled in NestedProcedure"
    Exit Sub
NestedErrorHandler:
    MsgBox "Error in NestedProcedure: " & Err.Number & " " & Err.Description
    Resume Next
End Sub

Sub NestedNestedProcedure()
    Err.Raise 400, , "Unhandled in NestedProcedure"
    On Error GoTo NestedNestedErrorHandler
    ' Code erroring here will be handled only by the NestedErrorHandler
    Err.Raise 500, , "Handled in NestedProcedure"
    Exit Sub
NestedNestedErrorHandler:
    MsgBox "Error in NestedNestedProcedure: " & Err.Number & " " & Err.Description
    Resume Next
End Sub

Err.Raise is behaving as expected in all the scenarios I tested. Each scenario is just me commenting out different Err.Raise lines to see what errors get caught where.

I was not able to get one of the lower level errors to jump over the main error handler and trigger the VBA catchall error dialog box with the Debug and End buttons. I can get that with an unhandled error in the MainProcedure.

On Error Resume Next seems to work as expected as well. Perhaps it has something to do with other code that is setting up classes and such and resetting pointers.

I suspect though that the developers are running the tests and presumably they would experience the problem as well, but maybe there’s something different about my environment. I am using vbWatchdog and the plugin is installed, although the code is not loaded in this project.