|
Please...... With all due respect, Barbara, OPM RPG error handling stinks. If somebody didn't already know that, your example makes that pretty clear. Your first example has flaws in the beginning section: > C INPSSR IFEQ '1' > C GOTO ENDPGM > C MOVEL'1' INPSSR 1 > C ELSE > C* .... report the error > C ENDIF The only code that will ever get executed here is in the ELSE condition because the second line issues a GOTO that skips over the third line which sets the condition indicating the routine has already been visited. The GOTOs have got to GO!!! At least, that's what's been said many, many times before. The whole idea of putting TAG points throughout the code so as to be able to GOTO any location in the code is so incredibly unwieldy that it's ludicrous to even think about coding applications that way. C Z-ADD1 RTNLOC C A real line of code C TAG00001 TAG C Z-ADD2 RTNLOC C A real line of code C TAG00002 TAG ... repeat these groups over and over and over... Then in the PSSR, a SELEC group with each of the potential return locations (this should be a good performer!). Lots of GOTOs and TAGs, with all kinds of in-line code that hopefully never does anything. I, for one, hope to never see this sort of arrangement. It's 2000, let's get on with the move to RPG IV where condition handlers take care of our problems. It would take nowhere near as long to learn and/or convert programs to RPG IV as it would take to manage RPG III code that's designed around an incredibly weak error handling model such as the PSSR. Besides, in the typical application, design and code isn't even adequate to handle the things it should handle such as at least coding an error indicator (that's ignored) on op-codes. This would at least prevent blowups for some things. So, if programmers can't even add an indicator to the end of a line they're already keying in, how can they be expected to code and manage some PSSR-driven, convoluted mess? Gary Guthrie bmorris@ca.ibm.com wrote: > > 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 > +--- +--- | 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-2025 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.