Solved

Error Trapping Break Modes

Posted on 2004-09-02
3
179 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
ID: 11961408
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
ID: 11961436
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
ID: 11961494
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access - Capture pressed key onclick 4 28
Run code from text file in vb 1 56
Macro Excel - Multiple If conditions 2 64
MsgBox 4 46
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

911 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

16 Experts available now in Live!

Get 1:1 Help Now