On error...

Creative ideas/suggestions for HMG

Moderator: Rathinagiri

User avatar
Rathinagiri
Posts: 5210
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 155 times
Been thanked: 144 times
Contact:

On error...

Post by Rathinagiri » Fri Feb 19, 2010 7:38 am

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:

Post by raumi75 » Fri Feb 19, 2010 8:16 am

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: 4439
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 324 times
Been thanked: 99 times
Contact:

Post by esgici » Fri Feb 19, 2010 8:21 am

Hi Rathi and Raumi

Did you tried BEGIN/END SEQUENCE structure ?

Regards

--

Esgici
Viva INTERNATIONAL HMG :D

User avatar
Rathinagiri
Posts: 5210
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 155 times
Been thanked: 144 times
Contact:

Post by Rathinagiri » Fri Feb 19, 2010 8:26 am

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: 3905
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 15 times
Been thanked: 140 times

Post by Roberto Lopez » Fri Feb 19, 2010 1:51 pm

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: 3905
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 15 times
Been thanked: 140 times

Post by Roberto Lopez » Fri Feb 19, 2010 1:56 pm

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: 5210
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 155 times
Been thanked: 144 times
Contact:

Post by Rathinagiri » Fri Feb 19, 2010 4:53 pm

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: 2993
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 162 times
Been thanked: 87 times
Contact:

Post by mol » Fri Feb 19, 2010 8:54 pm

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: 4439
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 324 times
Been thanked: 99 times
Contact:

Post by esgici » Thu Jul 19, 2012 12:12 pm

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

Post by Rossine » Thu Jul 19, 2012 12:31 pm

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