Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error Handling

0 views
Skip to first unread message

Sam

unread,
Jul 9, 2002, 2:34:00 PM7/9/02
to
I frequently see two versions of error-handling code:

On Error GoTo ErrorHandler
---do something here
Exit_MyProcedure_Click:
Exit Sub
ErrorHandler:
Do something here
Resume Exit_MyProcedure_Click
End Sub

AND

On Error GoTo ErrorHandler
--do something here
ErrorHandler:
Do something here
Resume Exit_MyProcedure_Click
End Sub

What is the purpose of the Exit_MyProcedure_Click:/Exit Sub part
and when is it needed?

Thanks Sam


Lars Reimer Jensen

unread,
Jul 10, 2002, 9:16:46 AM7/10/02
to
When you run a sub with error handling, you have to have a section, that
takes care of the error and then
resumes with code, that needs to be run whether or not there's an error.
This code you can place in the Exit_MyProcedure_Click: part.
If there is no error, then the codes runs until it hits the Exit Sub
statement. This terminates the sub skipping the code that takes care of the
error.
On the other hand if there is an error, then it jumps to the ErrorHandler:
runs this code and then jumps to the Exit_MyProcedure_Click: part to finish
the code.

To sum it up a bit:
If you use error handling, then the Exit_MyProcedure_Click: part is needed.
if not you can skip the Exit_MyProcedure_Click: part

Hope this was clear enough.

Regards,

Lars Reimer Jensen.

P.S.

2nd version
.....
> Resume Exit_MyProcedure_Click

I don't think this statement will be present, if you don't have the
Exit_MyProcedure_Click label,
so I've just ignored it.


"Sam" <s...@playitagain.com> skrev i en meddelelse
news:s0GW8.1765$Kx3...@newsread1.prod.itd.earthlink.net...

0 new messages