Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

Error Handler

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
RuschWEB
Asked:
RuschWEB
1 Solution
 
TimCotteeCommented:
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
 
WHalphenCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now