Solved

Error Trapping Break Modes

Posted on 2004-09-02
3
178 Views
Last Modified: 2010-05-02
I am going through my code and adding all my error handlers and to turn on "break on all errors" and found a piece of code breaking and saying "Element not found"

the peice of code is from a question i asked:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21110708.html

and is in the final section:
Public Function SafeGetNode(Ind As Variant) As Node
    On Error Resume Next
    Set SafeGetNode = TreeView1.Nodes.Item(Ind)          '<---this line here errors
End Function

So my question is:

Should I go through testing and validating my code using "Break on all errors"? and if yes... how do i fix this error?

Cheers,

`Andy
0
Comment
Question by:xizor
  • 2
3 Comments
 
LVL 8

Expert Comment

by:mladenovicz
Comment Utility
Use Break in Class Module.

Break on All Errors &#8212; Any error causes the project to enter break mode, whether or not an error handler is active and whether or not the code is in a class module.

Break in Class Module &#8212; Any unhandled error produced in a class module causes the project to enter break mode at the line of code in the class module which produced the error.
When you debug an ActiveX component project by running an ActiveX client test program in another project, set this option in the ActiveX component project to break on errors in its class modules, instead of always returning the error to the client test program.

Break on Unhandled Errors &#8212; If an error handler is active, the error is trapped without entering break mode. If there is no active error handler, the error causes the project to enter break mode. An unhandled error in a class module, however, causes the project to enter break mode on the line of code that invoked the offending procedure of the class.
0
 
LVL 2

Author Comment

by:xizor
Comment Utility
Yeah, i read all that in the help, but can you tell me why?
0
 
LVL 8

Accepted Solution

by:
mladenovicz earned 50 total points
Comment Utility
Well, You have this function

Public Function SafeGetNode(Ind As Variant) As Node
    On Error Resume Next
    Set SafeGetNode = TreeView1.Nodes.Item(Ind)          '<---this line here errors
End Function

This function should not report error. If node exists it will be returned. If it does not exists function will return Nothing.

If you choose Break On All errors, your function will report error, but it should not cause you handle this error.

However, if you choose break in class module, if an  error occurs (not handled by your error hanlder), application will  break on the line that cause error. If you choose Break on Unhandled Errors, if an erro roccurss, application will break on the line that calls function where error occurred. I like to see the line where error occurred immediately, that's why I am using Break in Class Module.

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

762 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

10 Experts available now in Live!

Get 1:1 Help Now