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

Chapter 16. Error Handling: Preparing fo... > Building a Custom Error Handler Clas...

Building a Custom Error Handler Class

Implementing error handling within an application can be very tedious, especially if you attempt to place specific error-handling logic in each routine you write. Although implementing a generic error handler does not mandate the use of a class module, using a class module greatly facilitates the process of implementing error handling within your applications. Listing 16.29 illustrates this point.

Listing 16.29. An Example of an Access Subroutine

Sub AnySub2()
'Declare constant with the name of the routine
Const SUBNAME As String = "AnySub"

'Invoke error handling
On Error GoTo AnySub2_Err

    'Beginning of any routine
    MsgBox "This is the rest of your code...."

    'Oops! Something causes an error!
    Err.Raise 11

    'Code after the error
    MsgBox "We are Past the Error!!"

AnySub2_Exit:
    'Generic exit point for routine
    Exit Sub

AnySub2_Err:
    Dim intAction As Integer

    'Instantiate the error handler class
    Set gobjErrorHandler = New ErrorHandler

    'Execute the ErrorProcess method,
    'passing the error information
    intAction = gobjErrorHandler.ErrorProcess(ModuleName, _
        SUBNAME, Err.Number, Err.Description)

    'Evaluate return value to determine what action to take
    Select Case intAction
        Case ERR_CONTINUE
            Resume Next
        Case ERR_RETRY
            Resume
        Case ERR_EXIT
            Resume AnySub2_Exit
        Case ERR_QUIT
            Quit
    End Select
End Sub


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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