Solved

Error Trapping Break Modes

Posted on 2004-09-02
3
183 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
[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
  • 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
Suggested Courses
Course of the Month5 days, 19 hours left to enroll

627 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