Solved

Error handling

Posted on 1998-10-07
1
160 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
[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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

749 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