Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handling - one module wide generic routine ?

Status
Not open for further replies.

shaunk

Programmer
Aug 20, 2001
402
AU
I have the standard error routine as follows:

Code:
Sub Do_Stuff()

On Error GoTo Err_Handler

    'sub procedure does stuff    

Endit:
    Application.Interactive = True
    Exit Sub
    
Err_Handler:
  
    MsgBox _
    "An unexpected error has been detected" & Chr(13) & _
    "Description is: " & Err.Number & " , " & Err.Description & Chr(13) & _
    "Module is: Do_Stuff" & Chr(13) & _
    "Please contact ShaunK with the above details"
    Resume Endit

Is there a way to write the error routine at the module level, so that any error occurring in any procedure is handled via this routine. This would save the need to rewrite much the same code in every sub procedure. I realise I would have to somehow pass the name of the failing procedure to the Error Handler. From previous posts, the name of the procedure is not exposed.

Thanks
 

You are correct that the name of the procedure is not exposed so you will have to arrange for that to be available somehow via hard code in each procedure.

The actual error trap itself can be put in the top level module and if there are no error traps lower down the hierarchy any error should trickle back up to the top level trap.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top