On error...

Creative ideas/suggestions for HMG

Moderator: Rathinagiri

User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

On error...

Post 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?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
raumi75
Posts: 135
Joined: Wed Dec 17, 2008 2:31 am
Location: Lünen, Germany
Contact:

Re: On error...

Post 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
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: On error...

Post by esgici »

Hi Rathi and Raumi

Did you tried BEGIN/END SEQUENCE structure ?

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: On error...

Post by Rathinagiri »

Nope Esgici. I will try. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: On error...

Post 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 )
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: On error...

Post 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
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: On error...

Post by Rathinagiri »

Thanks Roberto. I will go through and use it.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: On error...

Post 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...
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: On error...

Post 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
Viva INTERNATIONAL HMG :D
Rossine
Posts: 87
Joined: Thu Jun 30, 2011 10:04 pm

Re: On error...

Post 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.
Post Reply