?
Solved

Error Handler

Posted on 2003-03-17
2
Medium Priority
?
248 Views
Last Modified: 2010-05-03
Where do I put the Error Handler so that it can be accessed throughout my entire program?
- from all different subs and functions, whenever an error occurs..
0
Comment
Question by:RuschWEB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 8151205
Hi RuschWEB,

You cannot, VB does not do this. You have to include error handling specifically in each sub/function etc.

If you were for example to start your application from Sub Main and only place error handling in this sub, any error that occurred would be handled in that it would return error control to that sub's error handler. However it *WILL NOT* then resume from the appropriate place in the sub or function that called it.

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com

Experts-Exchange Advisory Board Member
0
 

Accepted Solution

by:
WHalphen earned 135 total points
ID: 8156257
You can have a centralized error processing routine that is called from the error handlers in the procedures.  Use the following structure for your code:

private sub dosomething()
   on error goto Err_dosomething
   ...your subroutine code here...
   Exit Sub
Err_dosomething:
   Call ErrorProcessingRoutine()
   Resume Next
End Sub


public ErrorProcessingRoutine()
   'error handling code
   Select Case Err.Number
      Case 1
         ...code to handle error 1...
      Case 2
         ...code to handle error 2...
      Case 3
         ...code to handle error 3...
   End Select
End Sub

With this approach you can leverage one set of error handlers for all of your procedures.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question