billw@hpcvra.cv.hp.com. (William C Wickes) (02/09/91)
A New IFERR for HP 48 "Bulletproofing" Several HP 48 programmers have expressed a concern that the current error trapping mechanism via IFERR is vulnerable to repeated ATTN key presses, which can prevent a program from cleaning up when it is interrupted by the user. This problem arises because IFERR and all other branching constructs built into the HP 48 check to see if ATTN key has been pressed so that users cannot (easily) lock themselves into an uninterruptible loop. The object listed below in ASC-> form is an HP 48 library titled "IF ERROR", which provides an alternate version of IFERR/THEN which can be uniformly substituted for the built-in versions. The difference between this version and that built into the HP 48 is in the handling of ATTN. The ATTN key check is disabled for the THEN clause of the version provided in this library, allowing for an "unbreakable" recursive error recovery. An example of this use is given in the program below. In the "main" program, a loop display a counter running from 1 to 1000. If you press ATTN while it is running, the error trap starts another counting loop, this time from 1 to 50, to show you that an error termination sequence of some length is running. If you interrupt it, it just restarts itself. In the first line, a temporary variable, et, is allocated. This variable will hold the error termination procedure after it is created in the next part of the program. The error termination procedure is simply a cleanup procedure protected by an IFERR which branches back to itself recursively if an error occurs in its execution. It is created in a list to avoid the inclusion of the opening and closing program quotes, which themselves have attention key checks. The remainder of the program is protected by IFERR...THEN et EVAL END. Notes: * You must access the error termination procedure via a temporary variable because global variable execution itself contains an attention key check. * If your cleanup procedure has an unavoidable error, the only way to stop infinite execution is by [ON]-[C]. * The library (which has ID 1793) is auto-attaching: to use it, all you need to do is store it in a port (port 0, say) by putting it on the stack and executing :0:1793 STO, and then turning the HP 48 off and on. * To convert old programs containing IFERR to the new version, you need only to EDIT (VISIT), then ENTER when the library is attached. Downloading a program in ASCII form via kermit will also automatically use the new IFERR. Sample error trap program: ----------------- cut here ---------------------------------------------- %%HP: T(3)A(R)F(.); \<< 0 \-> et \<< { IFERR 1 50 FOR j "YOUR CLEANUP PROC." 1 DISP "#" j \->STR + " HERE" + 2 DISP NEXT THEN et EVAL ELSE DONE END } OBJ\-> DROP 'et' STO IFERR 1 1000 FOR j "YOUR MAIN PROC." 1 DISP "#" j \->STR " NOW" + + 2 DISP NEXT THEN et EVAL END \>> \>> ----------------- cut here ---------------------------------------------- IF ERROR Library: ----------------- cut here ---------------------------------------------- %%HP: T(3)A(R)F(.); "04B201220080946402542525F425801074100000000F8000DA000E4A20080000 0000000000000064000E40000000000000000000000000000000000000000000 0000000000000001200040458454E4100509464542525000F000012000E4A20E 100093000B90005A000FC000D0100D9D20119201070090770B21309107000D9D 20E1A81BEE60E5E40E8F608BE40D9D20EB78309146D18837BF60B21300883608 8362B336B213029E20107200E38412107100D9D20E1A81B2130D9D20A025229E 20107000E03521DF6029E20107300B2130D9D20A435210CB04345206DB029E20 107400E2A32FCCB01DF6029E20107300B2130D9D20A5252223524423063352A0 25229E20107100E03521DF607D042B21306C9DC133" ----------------- cut here ---------------------------------------------- Bill Wickes HP Corvallis
billw@hpcvra.cv.hp.com. (William C Wickes) (02/23/91)
As pointed out by Kevin Bashi, this version of IFERR has a bug which prevents its use in situations where command line execution is pending. Please discard this library. We will post a corrected version soon.