Repository navigation
Error Handling
Daniel Long edited this page Sep 29, 2026
·
4 revisions
MONITOR;
result = numerator / denominator;
ON-ERROR;
DSPLY 'Division error!';
result = 0;
ENDMON;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).
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;DUMP writes a formatted dump of the program's variables -- but, as on IBM i,
only when the program is compiled with CTL-OPT DEBUG(*YES) (or DEBUG(*DUMP),
or H DEBUG in fixed format), or when the operation is DUMP(A). Otherwise it
does nothing, so DUMP statements can stay in a program and only fire in a
debug build. IBM i writes the dump to a spooled file; OpenRPG prints it.
CTL-OPT DEBUG(*YES);
DUMP; // dumps: DEBUG(*YES)
DUMP(A); // dumps whatever DEBUG says- Installation
- Quick Start
- CLI Reference
- Language Basics
- Data Types
- Variables and Constants
- Data Structures
- Arrays
- Varying-Dimension Arrays
- Control Flow
- Procedures
- Procedure Overloading
- Built-In Functions
- Error Handling
- Operation Extenders
- Enumerations
- Program Status Data Structure
- Data Areas
- SND-MSG
- Embedded SQL
- Record-Level Access
- Display Files (WORKSTN)
- Program-Described Files (I-Specs and O-Specs)
- DATA-INTO and DATA-GEN
- XML-INTO
- Fixed-Format Source
- Database Connections
- Multi-Module Programs
- Environment Variables
- Testing
- Complete Example: Employee Report
- IBM i Conformance Results
- IBM i Execution Results