I have an error handler that gives the user the option of closing the
current form and continuing. I am using the Release method of the
current form to release the activeform. However, the problem is that
even after using the release method, whatever procedure was running in
the activeform continues running through to the end of the procedure.
When that procedure finishes, the form will be released. The problem
is, the user might end up getting multiple error messages before the
form releases.

Is there any way to stop the form from running through all the code in
the current procedure before releasing?

Kevin Clark
Seton Home Study School

Re: Error Handling by Dennis

Dennis
Wed Jun 29 11:18:18 CDT 2005

Hi--

If your error handler does not abort VFP, it's going to be tough to get it
to bypass all remaining code for the form. There is no method that says
"close this form now and don't run any more code".

If you're sure that further code execution with or without errors isn't
going to hurt anything, you could set your error handler to simply ignore
all further errors. If your handler is in the form's Error event, simply
return out of it. If you are using
ON ERROR DO ....,
set it to ON ERROR *

Hope this helps!

Dennis

<KevClark64@hotmail.com> wrote in message
news:1120054965.451247.269100@g14g2000cwa.googlegroups.com...
>I have an error handler that gives the user the option of closing the
> current form and continuing. I am using the Release method of the
> current form to release the activeform. However, the problem is that
> even after using the release method, whatever procedure was running in
> the activeform continues running through to the end of the procedure.
> When that procedure finishes, the form will be released. The problem
> is, the user might end up getting multiple error messages before the
> form releases.
>
> Is there any way to stop the form from running through all the code in
> the current procedure before releasing?
>
> Kevin Clark
> Seton Home Study School
>



Re: Error Handling by Olaf

Olaf
Wed Jun 29 15:38:37 CDT 2005

> Is there any way to stop the form from running through all the code in
> the current procedure before releasing?

If you have your READ EVENTS in the main.prg
running at topmost level, you may simply RETURN TO MASTER
in your Errorhandler, and that will get you back to that READ EVENTS
without the rest of a procedure running.

But I wouldn't work that way, as this gives the risk of loosing data and
more. Think of unfinished transactoins, dangling object references.
The result could be worse than decent error handling and graceful quit
of the whole application instead of continuing to work under unknown
conditions, which would make C5 errors probable and they can lead
to serious defects of tables...

Just a demo of how RETURN TO MASTER could work:
If you run this, click on the ZAP button, that will Zap a nonexisting
alias and thereby create an Error, handled by loForm.command1.Error,
which will then call Thisform.Error() and that asks, if you want to quit
the form. If not, the correct cursor alias is zapped, if you quit, the
debugger will open just before the RETURN TO MASTER and you
can see where that leads you (to the inital programm, that is to the READ
EVENTS line):

LOCAL loForm
loForm = CREATEOBJECT("returntomasterform")
loForm.show()
READ EVENTS

DEFINE CLASS returntomasterform AS form
Top = 20
Left = 20
Height = 242
Width = 360
DoCreate = .T.
Caption = "Form1"
Name = "Form1"

ADD OBJECT command1 AS commandbutton WITH ;
Top = 204, ;
Left = 264, ;
Height = 27, ;
Width = 84, ;
Caption = "ZAP", ;
Name = "Command1"

ADD OBJECT grid1 AS grid WITH;
Height = 180, ;
Left = 12, ;
Top = 12, ;
Width = 336, ;
Name = "Grid1"

PROCEDURE Load
CREATE CURSOR curTest (cText1 C(10), cText2 C(10))
INSERT INTO curTest VALUES ("hello","world")
ENDPROC

PROCEDURE Error
LPARAMETERS nError, cMethod, nLine
IF MESSAGEBOX("an error occured. Want to quit this form?",4)=6
THISFORM.Release()
SET STEP ON
RETURN TO MASTER
ELSE
RETURN
ENDIF
ENDPROC

PROCEDURE command1.Click
ZAP IN curText
MESSAGEBOX("oops, i should have zapped curTest")
ZAP IN curTest
ENDPROC

PROCEDURE command1.Error
LPARAMETERS nError, cMethod, nLine
Thisform.Error(nError, cMethod, nLine)
ENDPROC

ENDDEFINE

Bye, Olaf.