Solved

Error handling

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses
Course of the Month3 days, 11 hours left to enroll

630 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