?
Solved

error handling

Posted on 2005-05-17
4
Medium Priority
?
146 Views
Last Modified: 2010-05-01
Hello All,
                 I have a question regarding error trapping. I observe that sometimes error hadlers extend thier power into subs they call. That makes it harder to work with particular errors . How do I ensure that error handlers work only locally, that is, in a procedure/function it's declared and do not cross over to any other subs/functions that they may be calling.  

Thank you.
Serge
0
Comment
Question by:Autofreak
4 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 200 total points
ID: 14020802
Before you call your subs/functions you can turn off error trapping and then turn it back on when the call returns.

To turn off error handling use:

    On Error Goto 0

Then turn it back on with:

    On Error Goto someLabelName
0
 
LVL 5

Assisted Solution

by:gary_j
gary_j earned 200 total points
ID: 14021112
Best bet is to error trap everything.
For example if Sub1 has an error handler and Sub1 calls Sub2, if Sub2 does not have its own error routine, the error will be returned to Sub1, making it very difficult to debug.  If Sub2 has its own error routine then the error will be handled in the place that it occurred.
0
 
LVL 5

Assisted Solution

by:codeconqueror
codeconqueror earned 200 total points
ID: 14027717
You can add something like this to each sub or function (just replace Exit Sub with Exit Function).  It won't give you the line numbers in the error but this will be the best you can do without using additional subs and such.

<CODE SNIPPET>
On Error Goto ErrHandler

'**** Insert your code here

Exit Sub

ErrHandler:
     msgbox "Error Description: " & err.description & vbcrlf & "Error Number: " & err.number
     err.clear
     exit sub '**** or change this to Resume Next if you want to try the next line
</CODE SNIPPET>
0
 

Author Comment

by:Autofreak
ID: 14069655
Thanks Guys, each answer is helpfull in its own way. Thanks to you i became a better trapper, I hope :)
Serge.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 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…
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…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

839 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