Discussion:
Error Handling
(too old to reply)
Kevin Clark
2010-11-30 19:30:53 UTC
Permalink
I have a form that uses ON ERROR to catch any errors not handled by
TRY ... CATCH.

When an error occurs within a method of the form, I would like to have
the option of unloading the form and not continuing the rest of the
lines in the method that caused by error. However, no matter what I
do, it seems that the current method is run to the end. Using UNLOAD
or RELEASE to try to clear the form from memory doesn't seem to do
anything.

Example:

x=x/0 && generates error and runs error handler
print "This line always runs when returning from error handler"

I would like to use form.release or form.unload or something else in
the error handler to unload the current form and prevent the method
from continuing.

Is there any way to do this?

Regards,
Kevin Clark
Dan Freeman
2010-11-30 20:22:50 UTC
Permalink
Foxpro's error handling does not work the way you want it to work and
no amount of fudging will change the way it works. Sorry.

One of the very best explanations of how it actually DOES work and what
you need to do to marshall the tools available to you is in Doug
Hennig's excellent article (with sample code) here:
www.stonefield.com/pub/errorh.zip

Dan
Post by Kevin Clark
I have a form that uses ON ERROR to catch any errors not handled by
TRY ... CATCH.
When an error occurs within a method of the form, I would like to have
the option of unloading the form and not continuing the rest of the
lines in the method that caused by error. However, no matter what I
do, it seems that the current method is run to the end. Using UNLOAD
or RELEASE to try to clear the form from memory doesn't seem to do
anything.
x=x/0 && generates error and runs error handler
print "This line always runs when returning from error handler"
I would like to use form.release or form.unload or something else in
the error handler to unload the current form and prevent the method
from continuing.
Is there any way to do this?
Regards,
Kevin Clark
Bernhard Sander
2010-11-30 20:35:33 UTC
Permalink
Hi Kevin,
Post by Kevin Clark
I have a form that uses ON ERROR to catch any errors not handled by
TRY ... CATCH.
When an error occurs within a method of the form, I would like to have
the option of unloading the form and not continuing the rest of the
lines in the method that caused by error. However, no matter what I
do, it seems that the current method is run to the end. Using UNLOAD
or RELEASE to try to clear the form from memory doesn't seem to do
anything.
Those methods of the form are not the right tools.
But have a look at RETURN TO some_proc in help.
some_proc can be any procedure somewhere up in the actual call stack and is
executed immediately.

Regards
Bernhard Sander
Zootal
2010-12-02 21:50:20 UTC
Permalink
Post by Kevin Clark
I have a form that uses ON ERROR to catch any errors not handled by
TRY ... CATCH.
When an error occurs within a method of the form, I would like to have
the option of unloading the form and not continuing the rest of the
lines in the method that caused by error. However, no matter what I
do, it seems that the current method is run to the end. Using UNLOAD
or RELEASE to try to clear the form from memory doesn't seem to do
anything.
x=x/0 && generates error and runs error handler
print "This line always runs when returning from error handler"
I would like to use form.release or form.unload or something else in
the error handler to unload the current form and prevent the method
from continuing.
Is there any way to do this?
Regards,
Kevin Clark
If the form is modal, you can run the form with an ON ERROR statement that
looks like this:

ON ERROR RETURN TO <some parent procedure>
DO FORM <MyForm>

An error will cause the executing code in the form to immediately stop
executing, and control will be returned to the parent procedure. You will
have to have a reference to the form, because the form will not terminate
(even though it is modal LOL), and you will need to clean up and close the
form manually. Somewhat kludgey, but with a bit of work you should be able
to get it to do what you want.

Continue reading on narkive:
Loading...