Structured Error Handling

Posted by Cherian George on 13-Jan-2020 20:39

Completely lost with structured error handling 

My .p code

/* *******************************************************************************************************************

DO TRANSACTION ON ERROR UNDO, THROW :
       IF NOT AVAILABLE gdcf_broadcast_point THEN
       DO:
              UNDO, THROW NEW Lib.JITSErr("Broadcast Point not found for " + gdcf_broadcast_point.brdp_id).
        END.
END.
CATCH e AS CLASS JITSErr:

       MESSAGE 'ERROR2' e:ReturnMsg().
        RETURN ERROR e:ReturnMsg().
END CATCH.

/* *******************************************************************************************************************

Now my Class

CLASS Lib.JITSErr INHERITS AppError:

/*------------------------------------------------------------------------------
Purpose:
Notes:
------------------------------------------------------------------------------*/
DEFINE VARIABLE vErrorMessage AS CHARACTER.

CONSTRUCTOR PUBLIC JITSErr ( Msg AS CHARACTER ):

         ASSIGN
        THIS-OBJECT:vErrorMessage = Msg.

END CONSTRUCTOR.

/*------------------------------------------------------------------------------
Purpose:
Notes:
------------------------------------------------------------------------------*/

METHOD OVERRIDE PUBLIC CHARACTER GetMessage( MsgNum AS INT ):
                 DEFINE VARIABLE result AS CHARACTER NO-UNDO.
                 result = THIS-OBJECT:vErrorMessage.
                 RETURN result.

END METHOD.

METHOD PUBLIC CHARACTER ReturnMsg( ):

                 DEFINE VARIABLE result AS CHARACTER NO-UNDO.

                 MESSAGE 'INSIDE RETURN MESSAGE'.
                 result = THIS-OBJECT:vErrorMessage.
                 RETURN result.

END METHOD.


END CLASS.

In the above example when the Catch Block in .p executes content of the Class member vErrorMessage is empty - Why would that be ??????????????

Thanks for all the help 

Posted by dbeavon on 13-Jan-2020 21:24

I'd recommend downloading the pdf about error handling: "Error Handling" under "ABL" heading:

https://community.progress.com/community_groups/openedge_general/w/openedgegeneral/2911.openedge-11-7-product-documentation

Remember that the inner-most opportunity for your CATCH block is within the DO TRANSACTION block that raises an error..  (That logic will be executed first, before control leaves to outer blocks).

This makes the code look very different from other languages with S.E.H.

Also remember to put this directive at the top of ever program: BLOCK-LEVEL ON ERROR UNDO, THROW.

All Replies

Posted by Stefan Drissen on 13-Jan-2020 20:53

1. you are attempting to include brdp_id when the record is not available - but this will just throw a run-time error

2. you have not specified NO-UNDO on vErrorMessag, so it gets undone.

See https://abldojo.services.progress.com:443/#/?shareId=5e1cd9404b1a0f40c34b8c22 for a running example.

Posted by Mike Fechner on 13-Jan-2020 20:55

Eveything that can be undone (no NO-UNDO variable) will be undone before getting into the CATCH block.

Posted by dbeavon on 13-Jan-2020 21:24

I'd recommend downloading the pdf about error handling: "Error Handling" under "ABL" heading:

https://community.progress.com/community_groups/openedge_general/w/openedgegeneral/2911.openedge-11-7-product-documentation

Remember that the inner-most opportunity for your CATCH block is within the DO TRANSACTION block that raises an error..  (That logic will be executed first, before control leaves to outer blocks).

This makes the code look very different from other languages with S.E.H.

Also remember to put this directive at the top of ever program: BLOCK-LEVEL ON ERROR UNDO, THROW.

Posted by Cherian George on 16-Jan-2020 07:58

Thank you all for your answers. Very Helpful.

Posted by Cherian George on 16-Jan-2020 07:58

Thank you all for your answers. Very Helpful.

This thread is closed