Repository navigation
Error Handling
Daniel Long edited this page Sep 24, 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;- 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