Solved

Error handling

Posted on 1998-10-07
1
158 Views
Last Modified: 2010-04-30
I have a sub A which calls sub B which calls sub C ... All of these procedures have an identical error handling routine which simply ends the procedure and logs the error description.  What I would want to happen is if the error occured in sub E, I don't want the program to still execute codes in D,C,B, then down to A to where it all started.  I wanted it to go to IMMEDIATELY to the line after the call to B.  Having it execute codes in D,C,B after an error in E generated quite disasterous results.  
0
Comment
Question by:imby
1 Comment
 
LVL 2

Accepted Solution

by:
schild earned 100 total points
ID: 1438783
Well Well Well
After years of procedure design, you want to break it all in one question.
If you where a VC programmer I would just laugh at that question and that all. But lucky you, you are VB programmer since so:
The VB exception  rule is If you insert exception handler in A and you didn’t do it in B either in C, but the exception occurred in B or C it will use the A’s exception. Which means all you have to do is

Private Sub A


on error goto ContinueRunFromHere
B


Exit Sub

ContinueRunFromHere
If Err.Number = 12345 the
      Resume Next
Else
      ‘This is a real excaption, do what ever you want to do
End If

End Sub


Private Sub E


      Err.Raise 12345

But please notice you must to be careful dealing with two more issues
1. The error number you put  in “Err.Raise 12345”, be careful it will not overlap an existing one (which mostly and not always have small values in standard VB code , but on in case of  OCXs exceptions ).
2. If you are using an exception handler in B, C, D or E, you must suspend those handlers before calling “Err.Raise 12345”
you do it like this

Private Sub B

On Error Goto WhoKnowWhere ‘This B’s normal exception handler

On Error Goto 0
C
On Error Goto WhoKnowWhere ‘Bring it back for use


End Sub


Good luck
Schild



0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 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