• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 16. Error Handling: Preparing fo... > Examining the Cascading Error Effect

Examining the Cascading Error Effect

As mentioned earlier in the section “Using On Error Statements,” if Access does not find any error handling in a particular subroutine or function, it looks up the call stack for a previous error handler. Listing 16.9 shows an example of this process.

Listing 16.9. Looking Up the Call Stack for a Previous Error Handler

Sub Func1()

    'Invoke error handling
    On Error GoTo Func1_Err

    'Print to the Immediate window
    Debug.Print "I am in Function 1"

    'Execute the Func2 routine
    Call Func2

    'Print to the Immediate window
    Debug.Print "I am back in Function 1"

    'Exit the subroutine
    Exit Sub

Func1_Err:
    'Display a message to the user,
    'indicating that an error occurred
    MsgBox "Error in Func1"

    'Resume execution
    Resume Next
End Sub

Sub Func2()
    'No error handling in this routine!
    'Print to the Immediate window
    Debug.Print "I am in Func2"

    'Execute Func3
    Call Func3

    'Print to the Immediate window
    Debug.Print "I am still in Func2"
End Sub

Sub Func3()
    'No error in this routine either!
    Dim sngAnswer As Single

    'Print to the Immediate window
    Debug.Print "I am in Func3"

    'Oops, an error occurred
    sngAnswer = 5 / 0

    'This line of code will never execute
    Debug.Print "I am still in Func3"
End Sub


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint