Solved

Error handling

Posted on 1998-10-07
1
155 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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now