Solved

Error Trapping Break Modes

Posted on 2004-09-02
3
182 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bit defender blocks good applications 2 107
VBA Shell can't Find Word document 11 131
Spell Check in VB6 13 137
Assign a value in Excel V-Basic 3 30
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…
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…
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…

730 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