Kbase P10422: How to trap the OUTPUT TO statement generated errors?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  15/10/2008 |
|
Status: Verified
GOAL:
How to trap OUTPUT TO statement errors? An OUTPUT TO...NO-ERROR simulation.
FIX:
The first of the following code samples allows the developer to trap for the error number and the second allows the developer to trap for the error message thus providing an opportunity to do error recovery and continue normal processing:
/****************A. Trap for the error number*********************/
DEFINE VARIABLE iErrNumber AS INTEGER NO-UNDO.
DEFINE STREAM myStream.
OUTPUT STREAM myStream TO "ErrorMessage.log" KEEP-MESSAGES.
MainBlock:
DO ON ERROR UNDO, RETRY:
IF RETRY THEN
DO:
OUTPUT STREAM myStream CLOSE.
LEAVE MainBlock.
END.
OUTPUT STREAM myStream TO myfile.txt.
END.
/* Replace following message statement with code */
/* defining corrective action based on error No. */
ASSIGN iErrNumber = _msg(1).
MESSAGE iErrNumber VIEW-AS ALERT-BOX INFO BUTTONS OK.
/******************************************************************/
/****************B. Trap for the error message********************/
DEFINE VARIABLE cVariable AS CHARACTER NO-UNDO.
DEFINE STREAM ErrorStream.
DEFINE STREAM OutputStream.
OUTPUT STREAM ErrorStream TO "ErrorMessage.log" KEEP-MESSAGES.
MainBlock:
DO ON ERROR UNDO, RETRY:
IF RETRY THEN
DO:
OUTPUT STREAM OutputStream CLOSE.
OUTPUT STREAM ErrorStream CLOSE.
LEAVE MainBlock.
END.
OUTPUT STREAM OutputStream TO myfile.txt.
END.
INPUT FROM VALUE("ErrorMessage.log") NO-ECHO.
IMPORT UNFORMATTED cVariable.
/* Replace following message statement with code */
/* for corrective action based on error message */
MESSAGE cVariable VIEW-AS ALERT-BOX INFO BUTTONS OK.
INPUT CLOSE.
/******************************************************************/