Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
On Error Resume Next | Excel Programming | |||
On Error Resume Next | Excel Programming | |||
On Error Resume Next | Excel Programming | |||
On Error Resume Next | Excel Programming | |||
On Error Resume Next | Excel Programming |