curzon@kaoa01.dec.com (Richard Curzon KAO4-3/7A DTN 621-2196) (07/28/87)
Re Marc Appelbaum's question on error handling in Action, here are 2 approaches at least: I got them from Bruce Langdon, who used to put lots of stuff in this newsgroup last year on the Action! language. If you want me to mail "the works" to you, send me personal mail. I don't normally receive the newsgroup mailings! ============================== One approach: ============================== BYTE OpOK ; flag for file opening error routinge PROC SysError(BYTE errno) ;used to save error Routine ;pointer below PROC MyError(BYTE errno) IF errno=$80 THEN Error=SysErr Error(errno) FI ; break quits PrintF("error %I. Try again%E",errno) OpOK=0 RETURN PROC Main() SysError = Error ; save old error handler vector Error = MyError ; replace it with MyError OpenFile() ; prompts for filename, and opens file ; after OPEN command, use something like: ;"IF OpOK THEN [go ahead] ; ELSE [prompt for filename again] ; FI" Error = SysError ;restore normal os error handler . . . ======================== another approach ======================== MODULE ; CATCH.ACT ; copyright (c) 1984 ; by Action Computer Services ; All Rights Reserved ; This module provides two PROCs ; (Catch and Throw) which can be used ; for error trapping (and flow ; control, yeck!) in ACTION!. To ; use them, you must call the Catch ; PROC to indicate where you want ; the program to continue when you ; call Throw. When throw is called, ; execution will continue following ; the last call to Catch with the ; same index as the call to Throw. ; Calling Catch is similar (but not ; identical) to TRAP in BASIC. It ; differs in that the actual trapping ; is generated by the user (by ; calling Throw) and that you can ; have multiple Catch'ers active at ; one time. Also, you cannot Throw ; to a Catcher that is no longer ; active (the PROC/FUNC containing ; it has RETURN to it's caller). The ; Throw procedure tries to check for ; this error, but it is possible to ; fool it into thinking it's OK. If ; you want to solve this problem, you ; can set 'c_t_sp(index)' to zero ; before you return from the PROC ; that contained the Catch(index). ; If index is greater than 24 or ; if there is no matching Catch index ; for the Throw, then Error will be ; called with a value of CTERR ; (defined below to be 71). If you ; setup your own Error procedure and ; use Catch and Throw, your error ; procedure should handle this error ; as well or your program will most ; likely "go off the deep end". DEFINE CTERR = "71" BYTE ARRAY c_t_sp(25)=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] BYTE ARRAY c_t_hi(25), c_t_lo(25) PROC Catch(BYTE index) DEFINE TSX="$BA", TXA="$8A", LDYA="$AC", STAY="$99", PLA="$68", LDAY="$B9", PHA="$48" IF index>=25 THEN Error(CTERR,0,CTERR) FI [ LDYA index PLA STAY c_t_hi PLA STAY c_t_lo TSX TXA STAY c_t_sp LDAY c_t_lo PHA LDAY c_t_hi PHA ] RETURN PROC Throw(BYTE index) DEFINE TXS="$9A", PHA="$48", LDYA="$AC", STX="$86", TSX="$BA", TAX="$AA", LDAY="$B9" BYTE sp=$A2 ; get current stack pointer [ TSX : STX sp ] IF index>=25 OR sp+2>c_t_sp(index) THEN Error(CTERR,0,CTERR) FI [ LDYA index LDAY c_t_sp TAX TXS LDAY c_t_lo PHA LDAY c_t_hi PHA ] RETURN MODULE ; for following code...