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

x
?
Solved

Debug

Posted on 1998-06-01
6
Medium Priority
?
137 Views
Last Modified: 2013-11-25
I have problem using On Error statement
I have 2 method:
Public Sub MethodA()
      :
      :
      On Error Resume Next
      :
      Call MethodB
      :
End Sub

Private sub MethodB()
      :
End sub

The on error statement also triggered in MethodB. How to stop that?
0
Comment
Question by:Cruiser
[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
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
yowkee earned 200 total points
ID: 1462273
 If you didn't put any "On Error" statement in MethodB, it would just follow the error handler of caller function. That's why the on error resume next still make sense in MethodB.

  Just put the Error Handler for MethodB, then it won't follow error handler of MethodA.

Public Sub MethodA()
:
On Error Resume Next
:
Call MethodB
:
End Sub

Private sub MethodB()
On Error GoTo ErrHandler
:
Exit Sub
ErrHandler:
:
:
End sub

0
 

Author Comment

by:Cruiser
ID: 1462274
let said I do not want any error handling in method B, how to do that?
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1462275
Cruiser,
 
  If you don't want any error handling in MethodB, just disable the error handler in MethodA before it call MethodB. But then any error in MethodB will handled by VB and may come out some unfriendly message to user.

Public Sub MethodA()
:
On Error Resume Next
:
On Error Goto 0  ' Disable error handler in this procedure
Call MethodB
On Error Resume Next  
:
End Sub


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Cruiser
ID: 1462276
Thanks
One last Q, what is the 'range' of a On Error statement?
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1462277
This is what stated in VB Help file:

---
On Error GoTo line
       Enables the error-handling routine that starts at line specified in the required line argument. The line argument is any line label or line number. If a run-time error occurs, control branches to line, making the error handler active. The specified line must be in the same procedure as the On Error statement; otherwise, a compile-time error occurs.

On Error Resume Next      
        Specifies that when a run-time error occurs, control goes to the statement immediately following the statement where the error occurred where execution continues. Use this form rather than On Error GoTo when accessing objects.
On Error GoTo 0      
        Disables any enabled error handler in the current procedure.

Remarks

If you don't use an On Error statement, any run-time error that occurs is fatal; that is, an error message is displayed and execution stops.
An "enabled" error handler is one that is turned on by an On Error statement; an "active" error handler is an enabled handler that is in the process of handling an error. If an error occurs while an error handler is active (between the occurrence of the error and a Resume, Exit Sub, Exit Function, or Exit Property statement), the current procedure's error handler can't handle the error. Control returns to the calling procedure. If the calling procedure has an enabled error handler, it is activated to handle the error. If the calling procedure's error handler is also active, control passes back through previous calling procedures until an enabled, but inactive, error handler is found. If no inactive, enabled error handler is found, the error is fatal at the point at which it actually occurred.

---
So, it depend which Error Handler is the current active Error Handler and which is enabled. If every procedure got on error statment, the range just within the procedure.
0
 

Author Comment

by:Cruiser
ID: 1462278
Thanks a lot
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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 …
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.
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

688 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