|
There are some good ways to control a *PSSR going back to some known point in the code if an expected error occurs, but I wonder if the effort is worth it. Any good scheme will ensure that only expected errors cause the program to continue. You need so much extra code to do this safely, and the extra code is necessarily mysterious, especially in RPG III where you have to use mangled names; therefore, I claim that it's better to add pre-checking to your code. I realize that not all exceptions are as simple to check for as division by zero, but for all the really complex operations like file I/O, where many different errors can occur, an error indicator is available. Here's the way I would write a PSSR (actual code to do the error reporting not included): C *PSSR BEGSR *-------------------------------------------------- * Make sure the PSSR doesn't get called again while * doing our error reporting and handling *-------------------------------------------------- C INPSSR IFEQ '1' C GOTO ENDPGM C MOVEL'1' INPSSR 1 C ELSE C* .... report the error C ENDIF C MOVEL'0' INPSSR C ENDPGM ENDSR'*CANCL' That said, I can't resist posting what I think is a pretty good PSSR setup. I think it has belt AND suspenders AND safety pins. Features: 1. Only allows pre-authorized errors to get handled 2. Error handling code is close to the location where the error occurred 3. All errors are reported (the reporting code isn't shown) except for errors that cause the PSSR to get called again 4. The PSSR is "safe" - it can't get into a loop 5. The program fails (ENDSR'*CANCL') if an unexpected error occurs. 6. Once the PSSR has been entered even for an expected error, the error is no longer expected, so it can't accidentally handle another error later. I SDS I *STATUS STATUS * Lxxxx: Error location to tell which Txxxx tag to goto * from the *PSSR if an expected error occurs * Sxxxx: Expected status code for the error I 0 C LNOEXP I 1 C LDIV0 I 102 C SDIV0 I 2 C LLEN0 I 100 C SLEN0 * ... Do a couple of safe operations C ADD 1 NUM 50 C Z-ADD0 DIVISR 50 *--------------------------------------------------- * We might get an error on the DIV operation ... *--------------------------------------------------- C EXSR CLRERR C Z-ADDLDIV0 ERRLOC C Z-ADDSDIV0 EXPSTS C NUM DIV DIVISR NUM C TDIV0 TAG C HADERR IFEQ '1' C* ... do something about the error C ENDIF * ... Do some more safe operations C ADD 1 NUM 50 C Z-ADD0 DIVISR 50 *-------------------------------------------------- * We might get an error on the SUBST operation too ... *-------------------------------------------------- C EXSR CLRERR C Z-ADDLLEN0 ERRLOC C Z-ADDSLEN0 EXPSTS C NUM SUBST'abc' FLD 5 C TLEN0 TAG C HADERR IFEQ '1' C* ... do something about the error C ENDIF *-------------------------------------------------- * End the program *-------------------------------------------------- C SETON LR *================================================== *================================================== * *INZSR * - Set up the PSSR stuff *================================================== *================================================== C *INZSR BEGSR C EXSR CLRERR C ENDSR *================================================== *================================================== * *PSSR * - branches back within the program if an error * was expected *================================================== *================================================== C *PSSR BEGSR C *LIKE DEFN ERRLOC PERRLC C *LIKE DEFN STATUS EXPSTS * Indicate that an error occurred C MOVEL'1' HADERR 1 *-------------------------------------------------- * Make sure the PSSR doesn't get called again while we are * doing our error reporting and handling *-------------------------------------------------- C INPSSR IFEQ '1' C GOTO ENDPGM C ELSE C MOVEL'1' INPSSR 1 C ENDIF C* C* .... report the error C* *-------------------------------------------------- * Copy the ERRLOC to the local PSSR copy and clear ERRLOC *-------------------------------------------------- C Z-ADDERRLOC PERRLC C Z-ADD0 ERRLOC *-------------------------------------------------- * If no ERRLOC was set or the expected status * doesn't match, end the program *-------------------------------------------------- C PERRLC IFEQ LNOEXP C STATUS ORNE EXPSTS C GOTO ENDPGM C ENDIF C SELEC C PERRLC WHEQ LDIV0 C GOTO TDIV0 C PERRLC WHEQ LLEN0 C GOTO TLEN0 C ENDSL *-------------------------------------------------- * Allow entry into the PSSR again *-------------------------------------------------- C MOVEL'0' INPSSR 1 C ENDPGM ENDSR'*CANCL' *================================================== *================================================== * CLRERR * - sets up error-handling to a "no-error" condition *================================================== *================================================== C CLRERR BEGSR C MOVEL'0' HADERR C MOVEL'0' INPSSR C Z-ADDLNOEXP ERRLOC C Z-ADD0 EXPSTS C ENDSR Barbara Morris +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.