Jezebel
Sun Dec 03 19:20:41 CST 2006
This is a multi-part message in MIME format.
------=_NextPart_000_000A_01C7179E.9D5BA8D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Not sure quite what you mean by 'working' in respect of TestA -- it =
ignores the first error, and jumps to SubErr for the second.
But the big issue, is that none of your error-handlers actually =
'handles' the error. An error is handled when the function exits or you =
execute a resume or resume [label] instruction. Until you do that, the =
code is still running within the context of the original-handler, and =
any further errors are passed 'up the line' to an error-handler in the =
calling function, if there is one. So a) the error-handler can't deal =
with errors within the error-handler itself, and b) you can't issue a =
new 'on error goto ...' within the context of the error-handling code. =
Try this --
Sub TestA()
On Error GoTo SubErr:
TestB
SubErr:
MsgBox "Error in Test A"
End Sub
Sub TestB()
On Error GoTo Err_Handler
Err.Raise 6
Err_Handler:
On Error GoTo Err_Handler:
MsgBox "Error in TestB"
Err.Raise 13
End Sub
The moral is, don't try to do clever things in the error-handling code: =
just handle the error and resume, either back to the code or to the exit =
point.
"Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message =
news:%23YeW2gzFHHA.960@TK2MSFTNGP04.phx.gbl...
Can someone help me understand why TestA works and TestB and TestC do =
not:
Sub TestA()
On Error Resume Next
Err.Raise 6
On Error GoTo SubErr:
Err.Raise 13
SubErr:
MsgBox "Eureka!!"
End Sub
Sub TestB()
On Error GoTo Err_Handler
Err.Raise 6
Err_Handler:
On Error GoTo SubErr:
Err.Raise 13
SubErr:
MsgBox "Eureka!!"
End Sub
Sub TestC()
On Error GoTo Err_Handler
Err.Raise 6
Err_Handler:
On Error Resume Next
Err.Raise 13
MsgBox "Eureka!!"
End Sub
In TestB and TestC, I have tried about every combination of GoTo, =
Resume, Err.Clear, that I can think of. I don't understand why the code =
isn't handling the second error. thanks.
--=20
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
------=_NextPart_000_000A_01C7179E.9D5BA8D0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2995" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#f8f2d6>
<DIV><FONT face=3DArial size=3D2>Not sure quite what you mean by =
'working' in=20
respect of TestA -- it ignores the first error, and jumps to SubErr for =
the=20
second.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>But the big issue, is that none of your =
error-handlers actually 'handles' the error. An error is handled =
when the=20
function exits or you execute a resume or resume [label] instruction. =
Until you=20
do that, the code is still running within the context of the =
original-handler,=20
and any further errors are passed 'up the line' to an error-handler in =
the=20
calling function, if there is one. So a) the error-handler can't deal =
with=20
errors within the error-handler itself, and b) you can't issue a new 'on =
error=20
goto ...' within the context of the error-handling code. Try this=20
--</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Sub TestA()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>On Error GoTo =
SubErr:<BR>TestB</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>SubErr:<BR>MsgBox "Error in Test =
A"<BR>End=20
Sub</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Sub TestB()<BR>On Error GoTo=20
Err_Handler<BR>Err.Raise 6</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Err_Handler:<BR>On Error GoTo=20
Err_Handler:<BR>MsgBox "Error in TestB"<BR>Err.Raise 13</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>End Sub</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>The moral is, don't try to do clever =
things in the=20
error-handling code: just handle the error and resume, either back to =
the code=20
or to the exit point.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Greg Maxey" <<A=20
=
href=3D"mailto:gmaxey@mvps.oSCARrOMEOgOLF">gmaxey@mvps.oSCARrOMEOgOLF</A>=
>=20
wrote in message <A=20
=
href=3D"news:%23YeW2gzFHHA.960@TK2MSFTNGP04.phx.gbl">news:%23YeW2gzFHHA.9=
60@TK2MSFTNGP04.phx.gbl</A>...</DIV>
<DIV>Can someone help me understand why TestA works and TestB and =
TestC do=20
not:</DIV>
<DIV> </DIV>
<DIV>Sub TestA()<BR>On Error Resume Next<BR>Err.Raise 6<BR>On Error =
GoTo=20
SubErr:<BR>Err.Raise 13<BR>SubErr:<BR>MsgBox "Eureka!!"<BR>End =
Sub<BR></DIV>
<DIV>Sub TestB()<BR>On Error GoTo Err_Handler<BR>Err.Raise=20
6<BR>Err_Handler:<BR>On Error GoTo SubErr:<BR>Err.Raise=20
13<BR>SubErr:<BR>MsgBox "Eureka!!"<BR>End Sub<BR></DIV>
<DIV>Sub TestC()<BR>On Error GoTo Err_Handler<BR>Err.Raise=20
6<BR>Err_Handler:<BR>On Error Resume Next<BR>Err.Raise 13<BR>MsgBox=20
"Eureka!!"<BR>End Sub<BR></DIV>
<DIV>In TestB and TestC, I have tried about every combination of GoTo, =
Resume,=20
Err.Clear, that I can think of. I don't understand why the code =
isn't=20
handling the second error. thanks.<BR>-- <BR>Greg Maxey/Word=20
MVP<BR>See:<BR><A=20
=
href=3D"
http://gregmaxey.mvps.org/word_tips.htm">http://gregmaxey.mvps.or=
g/word_tips.htm</A><BR>For=20
some helpful tips using Word.<BR></DIV></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_000A_01C7179E.9D5BA8D0--