Skip to content

Error Handling

Daniel Long edited this page Sep 24, 2026 · 4 revisions

Error Handling

MONITOR / ON-ERROR

MONITOR;
  result = numerator / denominator;
ON-ERROR;
  DSPLY 'Division error!';
  result = 0;
ENDMON;

*PSSR (Program Status Subroutine)

BEGSR *PSSR;
  DSPLY ('Unhandled error: ' + %CHAR(%STATUS));
ENDSR;

Subroutines, *PSSR included, come after all other calculations in their procedure: once the first BEGSR appears, only more subroutines may follow. As on IBM i, a statement after an ENDSR is an error (RNF5005).

ON-EXIT

DCL-PROC ProcessData;
  DCL-PI *N;
  END-PI;
  DCL-S abnormal IND;

  // ... processing ...

  ON-EXIT abnormal;
    IF abnormal;
      DSPLY 'Procedure ended abnormally';
    ENDIF;
    // cleanup code always runs
END-PROC;

Clone this wiki locally