Solved

Debug

Posted on 1998-06-01
6
131 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 50 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

624 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