Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error Trapping Break Modes

Posted on 2004-09-02
3
Medium Priority
?
185 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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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

722 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