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.