Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default On Error Resume Next

If I use "On Error Resume Next" in a public function, does "On Error Resume
Next" remain in effect after stepping out from the function, or have I to
explicitely make it ineffective with an "On Error Goto 0" statement before
steeping out from the function?
Thanks,
Stefi


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default On Error Resume Next

"Stefi" wrote in message
...
If I use "On Error Resume Next" in a public function, does "On Error
Resume
Next" remain in effect after stepping out from the function, or have I to
explicitely make it ineffective with an "On Error Goto 0" statement before
steeping out from the function?


Hi Stefi,

The effect of On Error Resume Next is generally confined to the
procedure where it is used. Once code exits that procedure it has the same
effect as the On Error Goto 0 statement. The one major exception to this
rule is when you call another procedure that has no error handling of its
own after an On Error Resume Next statement. In this case, an error in the
called procedure (the one with no error handling) will cause code execution
to silently bail out of that procedure and continue on the next line in the
calling procedure (the one where On Error Resume Next is in operation).

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default On Error Resume Next

Thanks Rob, it's clear. But the exception you mentioned is not really an
exception, because the code did not exit the procedure with the "On Error
Resume Next" in operation, so the original rule prevails: "On Error Resume
Next" remains in effect until exiting the procedure it was used in, OR the
code execution reaches another "On Error" statement that explicitly override
the original "On Error Resume Next".
Am I right?

Regards,
Stefi

Rob Bovey ezt *rta:

"Stefi" wrote in message
...
If I use "On Error Resume Next" in a public function, does "On Error
Resume
Next" remain in effect after stepping out from the function, or have I to
explicitely make it ineffective with an "On Error Goto 0" statement before
steeping out from the function?


Hi Stefi,

The effect of On Error Resume Next is generally confined to the
procedure where it is used. Once code exits that procedure it has the same
effect as the On Error Goto 0 statement. The one major exception to this
rule is when you call another procedure that has no error handling of its
own after an On Error Resume Next statement. In this case, an error in the
called procedure (the one with no error handling) will cause code execution
to silently bail out of that procedure and continue on the next line in the
calling procedure (the one where On Error Resume Next is in operation).

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default On Error Resume Next

"Stefi" wrote in message
...
Thanks Rob, it's clear. But the exception you mentioned is not really an
exception, because the code did not exit the procedure with the "On Error
Resume Next" in operation, so the original rule prevails: "On Error Resume
Next" remains in effect until exiting the procedure it was used in, OR the
code execution reaches another "On Error" statement that explicitly
override
the original "On Error Resume Next".
Am I right?


Hi Stefi,

Yes, you are correct..

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default On Error Resume Next

Ummm...kinda. The error trapping remains effective but in the scope of
the *sub that set it.* So, as Rob mentioned in his first post, control
immediately returns to the next statement in the *calling* procedure.
To illustrate:

Sub SetOnError()
Dim y
On Error Resume Next
CalledRoutine y
MsgBox y
End Sub
Sub CalledRoutine(ByRef x)
x = 1 / 0
x = x + 1
End Sub

The x=x+1 statement is *not* executed, the sequence of statements
being:
enable error trapping
call CalledRoutine
divide 1 by zero
resume with Msgbox statement in calling procedure.

On the other hand, if you added error handling to CalledRoutine a la

Sub CalledRoutine(ByRef x)
On Error Resume Next
x = 1 / 0
x = x + 1
End Sub

The MsgBox would show 1.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Thanks Rob, it's clear. But the exception you mentioned is not really an
exception, because the code did not exit the procedure with the "On Error
Resume Next" in operation, so the original rule prevails: "On Error Resume
Next" remains in effect until exiting the procedure it was used in, OR the
code execution reaches another "On Error" statement that explicitly override
the original "On Error Resume Next".
Am I right?

Regards,
Stefi

Rob Bovey ezt *rta:

"Stefi" wrote in message
...
If I use "On Error Resume Next" in a public function, does "On Error
Resume
Next" remain in effect after stepping out from the function, or have I to
explicitely make it ineffective with an "On Error Goto 0" statement before
steeping out from the function?


Hi Stefi,

The effect of On Error Resume Next is generally confined to the
procedure where it is used. Once code exits that procedure it has the same
effect as the On Error Goto 0 statement. The one major exception to this
rule is when you call another procedure that has no error handling of its
own after an On Error Resume Next statement. In this case, an error in the
called procedure (the one with no error handling) will cause code execution
to silently bail out of that procedure and continue on the next line in the
calling procedure (the one where On Error Resume Next is in operation).

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default On Error Resume Next

Hi Tushar,

That doesn't conflict at all what I wrote:

In your example 1
"On Error Resume Next" remained effective in the scope of the *sub that set
it* - including procedure calling (CalledRoutine y) -, because the code did
not exit the procedure the "On Error Resume Next" was set in.

In your example 2
"On Error Resume Next" set in the calling sub didn't remain effective,
because the code execution reached another "On Error" statement that
explicitly overrode
the original "On Error Resume Next".

Regards,
Stefi

Tushar Mehta ezt *rta:

Ummm...kinda. The error trapping remains effective but in the scope of
the *sub that set it.* So, as Rob mentioned in his first post, control
immediately returns to the next statement in the *calling* procedure.
To illustrate:

Sub SetOnError()
Dim y
On Error Resume Next
CalledRoutine y
MsgBox y
End Sub
Sub CalledRoutine(ByRef x)
x = 1 / 0
x = x + 1
End Sub

The x=x+1 statement is *not* executed, the sequence of statements
being:
enable error trapping
call CalledRoutine
divide 1 by zero
resume with Msgbox statement in calling procedure.

On the other hand, if you added error handling to CalledRoutine a la

Sub CalledRoutine(ByRef x)
On Error Resume Next
x = 1 / 0
x = x + 1
End Sub

The MsgBox would show 1.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Thanks Rob, it's clear. But the exception you mentioned is not really an
exception, because the code did not exit the procedure with the "On Error
Resume Next" in operation, so the original rule prevails: "On Error Resume
Next" remains in effect until exiting the procedure it was used in, OR the
code execution reaches another "On Error" statement that explicitly override
the original "On Error Resume Next".
Am I right?

Regards,
Stefi

âžRob Bovey❠ezt Ã*rta:

"Stefi" wrote in message
...
If I use "On Error Resume Next" in a public function, does "On Error
Resume
Next" remain in effect after stepping out from the function, or have I to
explicitely make it ineffective with an "On Error Goto 0" statement before
steeping out from the function?

Hi Stefi,

The effect of On Error Resume Next is generally confined to the
procedure where it is used. Once code exits that procedure it has the same
effect as the On Error Goto 0 statement. The one major exception to this
rule is when you call another procedure that has no error handling of its
own after an On Error Resume Next statement. In this case, an error in the
called procedure (the one with no error handling) will cause code execution
to silently bail out of that procedure and continue on the next line in the
calling procedure (the one where On Error Resume Next is in operation).

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default On Error Resume Next

{shrug}
This wasn't meant to be a war of semantics.

If you are happy with your interpretation of how error handling works,
good for you.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Hi Tushar,

That doesn't conflict at all what I wrote:

In your example 1
"On Error Resume Next" remained effective in the scope of the *sub that set
it* - including procedure calling (CalledRoutine y) -, because the code did
not exit the procedure the "On Error Resume Next" was set in.

In your example 2
"On Error Resume Next" set in the calling sub didn't remain effective,
because the code execution reached another "On Error" statement that
explicitly overrode
the original "On Error Resume Next".

Regards,
Stefi

Tushar Mehta ezt *rta:

Ummm...kinda. The error trapping remains effective but in the scope of
the *sub that set it.* So, as Rob mentioned in his first post, control
immediately returns to the next statement in the *calling* procedure.
To illustrate:

Sub SetOnError()
Dim y
On Error Resume Next
CalledRoutine y
MsgBox y
End Sub
Sub CalledRoutine(ByRef x)
x = 1 / 0
x = x + 1
End Sub

The x=x+1 statement is *not* executed, the sequence of statements
being:
enable error trapping
call CalledRoutine
divide 1 by zero
resume with Msgbox statement in calling procedure.

On the other hand, if you added error handling to CalledRoutine a la

Sub CalledRoutine(ByRef x)
On Error Resume Next
x = 1 / 0
x = x + 1
End Sub

The MsgBox would show 1.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Thanks Rob, it's clear. But the exception you mentioned is not really an
exception, because the code did not exit the procedure with the "On Error
Resume Next" in operation, so the original rule prevails: "On Error Resume
Next" remains in effect until exiting the procedure it was used in, OR the
code execution reaches another "On Error" statement that explicitly override
the original "On Error Resume Next".
Am I right?

Regards,
Stefi

â=3F=3FRob Boveyâ=3F ezt =3F*rta:

"Stefi" wrote in message
...
If I use "On Error Resume Next" in a public function, does "On Error
Resume
Next" remain in effect after stepping out from the function, or have I to
explicitely make it ineffective with an "On Error Goto 0" statement before
steeping out from the function?

Hi Stefi,

The effect of On Error Resume Next is generally confined to the
procedure where it is used. Once code exits that procedure it has the same
effect as the On Error Goto 0 statement. The one major exception to this
rule is when you call another procedure that has no error handling of its
own after an On Error Resume Next statement. In this case, an error in the
called procedure (the one with no error handling) will cause code execution
to silently bail out of that procedure and continue on the next line in the
calling procedure (the one where On Error Resume Next is in operation).

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
On Error Resume Next rcalvanese Excel Programming 3 April 11th 05 11:21 PM
On Error Resume Next Mike Archer[_2_] Excel Programming 3 March 2nd 05 01:41 PM
On Error Resume Next Jim Sharrock Excel Programming 2 May 13th 04 03:12 PM
On Error Resume Next D.S.[_3_] Excel Programming 1 November 28th 03 04:52 PM
On Error Resume Next Mike[_58_] Excel Programming 3 November 23rd 03 05:09 PM


All times are GMT +1. The time now is 01:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"