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
I'd recommend downloading the pdf about error handling: "Error Handling" under "ABL" heading:
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.
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.
Eveything that can be undone (no NO-UNDO variable) will be undone before getting into the CATCH block.
I'd recommend downloading the pdf about error handling: "Error Handling" under "ABL" heading:
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.
Thank you all for your answers. Very Helpful.
Thank you all for your answers. Very Helpful.