Page 1 of 6
On error...
Posted: Fri Feb 19, 2010 7:38 am
by Rathinagiri
In HMG, can we have some error catching blocks (like try...catch... in Java) that shall be executed before the application is closed abruptly?
For operations like saving some files, closing the database connections, re-encrypt the decrypted files?
Re: On error...
Posted: Fri Feb 19, 2010 8:16 am
by raumi75
That is a question I have asked myself many times.
Is use the clipper command
Code: Select all
ERRORBLOCK({ |oErr| MyOnError(oErr)})
To log real serious errors.
How do you guys catch errors?
Raumi
Re: On error...
Posted: Fri Feb 19, 2010 8:21 am
by esgici
Hi Rathi and Raumi
Did you tried BEGIN/END SEQUENCE structure ?
Regards
--
Esgici
Re: On error...
Posted: Fri Feb 19, 2010 8:26 am
by Rathinagiri
Nope Esgici. I will try.
Re: On error...
Posted: Fri Feb 19, 2010 1:51 pm
by Roberto Lopez
I use this in IDE to report preview and works perfectly (I've adapted from an old Clipper sample.
Code: Select all
bSaveHandler := errorblock( { |x| break(x) } )
BEGIN SEQUENCE
* This is the code to execute that could fail
EXECUTE REPORT _TempReport PREVIEW
DELETE FILE RePreviewSemaforo.Txt
<...>
RECOVER USING oError
* This is the code to execute if the above code fails
MSGSTOP( oError:Description + " " + oError:Operation , "Report Error:" )
DELETE FILE RePreviewSemaforo.Txt
Exit Program
END
errorblock( bSaveHandler )
Re: On error...
Posted: Fri Feb 19, 2010 1:56 pm
by Roberto Lopez
A more useful sample is shown in Clipper manual:
Code: Select all
This example demonstrates an error handler returning an error
object to the variable specified in the USING clause of the RECOVER
statement:
LOCAL objLocal, bLastHandler
//
// Save current and set new error handler
bLastHandler := ERRORBLOCK({ |objErr| ;
MyHandler(objErr, .T.) })
//
BEGIN SEQUENCE
.
. <operation that might fail>
.
RECOVER USING objLocal
//
// Send messages to objLocal and handle the error
? "Error: "
IF objLocal:genCode != 0
?? objLocal:description
ENDIF
.
.
.
END
//
// Restore previous error handler
ERRORBLOCK( bLastHandler )
FUNCTION MyHandler( objError, lLocalHandler )
//
// Handle locally returning the error object
IF lLocalHandler
BREAK objError
ENDIF
.
. <other statements to handle the error>
.
RETURN NIL
Re: On error...
Posted: Fri Feb 19, 2010 4:53 pm
by Rathinagiri
Thanks Roberto. I will go through and use it.
Re: On error...
Posted: Fri Feb 19, 2010 8:54 pm
by mol
I'm using errorblock and begin/end sequence.
In one of my latest projects I've added sending e-mail with error to me, when something wrong is going on...
Re: On error...
Posted: Thu Jul 19, 2012 12:12 pm
by esgici
Hi Rathi
A little (!?) late answer (because just added) :
a short compilation about error handling
I hope that will be useful
Regards
--
Esgici
Re: On error...
Posted: Thu Jul 19, 2012 12:31 pm
by Rossine
Hello all,
This interests me
It would be possible to assemble a complete example to demonstrate this new method using error control and the old ?
Best Regards,
Rossine.