Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handler re-loads program...

Status
Not open for further replies.

VBFOXDEV35

Programmer
Mar 26, 2001
77
US
Good afternoon. I have an application that runs in the system tray and waits for a particular call from a user or other independent program. If an error occurs, I want the program to basically re-load itself (as if you were to launch it from scratch). In the error handler I return to MASTER, which when finished goes through the call stack, returns to the initial read events line in my main.prg, then exits.
Main.prg
DO FORM frmSplash NAME gfrmSplash LINKED
READ EVENTS
RETURN <-----
the error handler returns here when the return to master is done. Then the program exits.

How can I get the program not to quit and just re-load? The error handler function is in the main program. Should I move the error handler to a different location other than main?
Any information would be greatly appreciated. Thanks

Arty

 
PUBLIC pcError
pcError = .t.
DO WHILE pcError
pcError = .f.
DO FORM frmSplash NAME gfrmSplash LINKED
READ EVENTS
ENDDO

In your Error catching routine.. add the line
pcError = .t.
CLEAR EVENTS

Hope this helps
ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
Ramani, but what if the program that is running is main.prg, and you want to re-start main.prg?

here is my example of what I mean...
This is the main.prg of the project

LPARAMETER strSwitches

* Declare / Initialize public variables
PUBLIC gfrmSplash
PUBLIC gstrFishDir && Main Fish folder (must be C:\WinFISH to work with CLAS)
gstrFishDir = SYS(5) + SYS(2003)

* Declare / Initialize local variables
LOCAL blnHidden
LOCAL lngCount
LOCAL strParam
LOCAL strTemp

* SET environment
SetSysData(&quot;SETHELP&quot;,!EMPTY(SET(&quot;HELP&quot;,1)))
DO SetEnv

* Allow only 1 instance of WinFISH
IF Single_Instance_App_By_Mutex(&quot;Clayton CLAS Reporter by Art and Jeff&quot;)
SetSysData(&quot;SHOWNOW&quot;,.t.)
QUIT
ENDIF

* Set global event handlers
ON SHUTDOWN DO ExitApp
ON ERROR DO HandleError WITH LINENO()

* Validate paths
DO CheckDir WITH gstrFishDir + &quot;\Data&quot;
DO CheckDir WITH gstrFishDir + &quot;\Lib&quot;
DO CheckDir WITH gstrFishDir + &quot;\Temp&quot;

* Process command line parameters
blnHidden = .f.
IF VarType(strSwitches) = &quot;C&quot; THEN
IF &quot;H&quot; $ UPPER(strSwitches) THEN
blnHidden = .t.
ENDIF
ENDIF

* Load the main form
IF blnHidden THEN
DO FORM frmSplash NAME gfrmSplash LINKED NOSHOW
ELSE
DO FORM frmSplash NAME gfrmSplash LINKED
ENDIF
SystemTray(&quot;INIT&quot;)
IF !EMPTY(GetSysData(&quot;CLASDIR&quot;)) THEN
OpenDeal(GetSysData(&quot;CLASDIR&quot;))
ENDIF
SetSysData(&quot;RUNNING&quot;,.T.)
READ EVENTS
RETURN <-- again here is where the call stack ends and then program exits

your example we do use in another application. The problem is we want to re-start MAIN in a sense eventhough main is running. I hope this makes sense.

Arty

 
I also forgot to mention the error may be fired off in another module, again brining you back to that return in the call stack.
 
Hi
I have not tried.. but just try this...
Instead of RETURN in the Error routines, can you replace it with RETRY. This could help to rerun the last command. ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
Ramani, retry brings me back to the line that created the error.

Could I create a blnHaveError variable and set it to .T. when an error occurs. then run my exitapp function but with the following code to re-start my application from startup:

PROCEDURE ExitApp
SetSysData(&quot;RUNNING&quot;,.F.)
SystemTray(&quot;CLOSE&quot;)
CLEAR EVENTS
IF VARTYPE(gfrmSplash) = &quot;O&quot; THEN
gfrmSplash.Release
ENDIF
CLOSE DATABASES
USE &gstrFishDir.\Data\SysData
IF SetHelp THEN
SET HELP TO
ENDIF
IF !Debug THEN
DELETE FILE &gstrFishDir.\Temp\*.*
ENDIF
REPLACE DealOpen WITH .f.
USE

** Program is done...close everything
RELEASE ALL
SET RESOURCE OFF
ON ERROR
ON SHUTDOWN

IF blnHaveError THEN
DO MAIN <-- start the beginning code in my second post?
ELSE
QUIT
ENDIF
RETURN


what do you think?

Arty
 
Ramani, I just tried the following after the return of the main.prg

DO WHILE blnHaveError
DO ExitApp <-- clears everything as if the app was to quit
DO Main
ENDDO

This actually works. I thought one could not call the main.prg if it was actually running or in this case was loaded. I guess by clearing and releasing all, including events, and then running the beginning of the application would have caused an error. I guess it does not.

Thanks for the help in getting me in the right direction!!!

Arty
 
The best thing to do, but this requires some rewriting of your program is the use of a global application object.

In your main you create the application object.

When an error occurs, you can destroy your global application object and recreate it, by recalling the procedure that created the global app object in the first place.

But this required an OOP handling of your VFP app.

What you can do also, in your case is the following:

Keep using your main program to start your app.
Handle your startup of your main forms etc in a separate procedure that is called from your main.

When an error occurs, call a procedure that cleans your environment and issue a CLEAR EVENTS , call your procedure that creates your main form etc. again.

THis could be placed in a DO WHILE loop as Ramani stated.

Example:
PUBLIC glExit

DO WHILE !glExit
*- Start app
ON ERROR DO On_Error
ON SHUTDOWN DO On_ShutDown
DO START
ENDDO

PROCEDURE START
*- Start your app
READ EVENTS
*- The app will continue here when a CLEAR EVENTS
*- is issued.
ENDPROC

PROCEDURE On_Error
*- handles your error routine
*----
*---
*- Set glExit and issue a CLEAR EVENTS
*- Your app will continue in the MAIN procedure
ENDPROC

PROCDURE On_ShutDown
*- You wish to shutdown
*- Clean up you environment
*- glExit = .T.
ENDPROC

HTH,
Weedz (Wietze Veld) They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best. - Steve McConnell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top