Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: RAERR01

RAERR01.m

Go to the documentation of this file.
  1. RAERR01 ;HCIOFO/SG - ERROR HANDLING UTILITIES ; 1/18/08 4:27pm
  1. ;;5.0;Radiology/Nuclear Medicine;**90**;Mar 16, 1998;Build 20
  1. ;
  1. Q
  1. ;
  1. ;***** RETURNS A LIST OF ERROR CODES FROM THE STACK
  1. ;
  1. ; [ENCLOSE] Enclose the list in commas.
  1. ;
  1. ; Return Values:
  1. ; "" No errors
  1. ; ... List of error codes (in reverse chronological order)
  1. ; separated by commas.
  1. ;
  1. ERRLST(ENCLOSE) ;
  1. N I,LST
  1. S I=" ",LST=""
  1. F S I=$O(RAERROR("ES",I),-1) Q:I'>0 D
  1. . S LST=LST_","_$P(RAERROR("ES",I,0),U)
  1. Q $S(LST="":"",$G(ENCLOSE):LST_",",1:$P(LST,",",2,999999))
  1. ;
  1. ;***** RETURNS THE TEXT AND TYPE OF THE MESSAGE
  1. ;
  1. ; ERRCODE Error code
  1. ;
  1. ; [.TYPE] Reference to a local variable where the problem
  1. ; type is returned ("I" - Information, "W" - warning,
  1. ; "E" - error).
  1. ;
  1. ; [ARG1-ARG5] Optional parameters that substitute the |n| "windows"
  1. ; in the text of the message (for example, the |2| will
  1. ; be substituted by the value of the ARG2).
  1. ;
  1. ; NOTE: The "^" is replaced with the "~" in the resulting message.
  1. ;
  1. MSG(ERRCODE,TYPE,ARG1,ARG2,ARG3,ARG4,ARG5) ;
  1. Q:ERRCODE'<0 ""
  1. N ARG,I1,I2,MSG
  1. ;--- Get a descriptor of the message
  1. S MSG=$$EZBLD^DIALOG(700000-(ERRCODE/1000))
  1. ;--- Parse and validate the descriptor
  1. S TYPE=$E(MSG),MSG=$P(MSG,U,2,999)
  1. S:("IWE"'[TYPE)!(TYPE="") TYPE="E"
  1. Q:MSG?." " "Unknown error ("_ERRCODE_")"
  1. ;--- Substitute parameters
  1. S I1=2
  1. F S I1=$F(MSG,"|",I1-1) Q:'I1 D
  1. . S I2=$F(MSG,"|",I1) Q:'I2
  1. . X "S ARG=$G(ARG"_+$TR($E(MSG,I1,I2-2)," ")_")"
  1. . S $E(MSG,I1-1,I2-1)=ARG
  1. Q $TR($$TRIM^XLFSTR(MSG),U,"~")
  1. ;
  1. ;***** DISPLAYS THE ERROR STACK OR A SINGLE ERROR MESSAGE
  1. ;
  1. ; [ERROR] Descriptor of a single error to be displayed.
  1. ;
  1. ; [.RAINFO] Reference to a local array with additional
  1. ; information for a single error.
  1. ;
  1. PRTERRS(ERROR,RAINFO) ;
  1. Q:($G(ERROR)'<0)&($D(RAERROR("ES"))<10)
  1. N EXIT,IMSG
  1. ;--- Print table header
  1. Q:$$PAGE^RAUTL22(3)<0
  1. D W^RAUTL22("Code Message")
  1. D W^RAUTL22(" Additional Information")
  1. D W^RAUTL22(" Location")
  1. D W^RAUTL22("---- "_$$REPEAT^XLFSTR("-",IOM-7))
  1. ;--- Print a single error message
  1. I $G(ERROR)<0 S EXIT=$$PRT1ERR(ERROR,"RAINFO") Q
  1. ;--- Print the error stack (most recent messages first)
  1. S IMSG=" " K EXIT
  1. F S IMSG=$O(RAERROR("ES",IMSG),-1) Q:IMSG'>0 D Q:$G(EXIT)
  1. . D:$D(EXIT) W^RAUTL22(" ")
  1. . S EXIT=$$PRT1ERR(RAERROR("ES",IMSG,0),$NA(RAERROR("ES",IMSG,1)))
  1. Q
  1. ;
  1. PRT1ERR(ERR,RA8INFO) ;
  1. N I,RC,SP6
  1. S RC=0,SP6=" "
  1. ;===
  1. D
  1. . S RC=$$PAGE^RAUTL22 Q:RC<0
  1. . D W^RAUTL22($J(+ERR,4)_" "_$$TRUNC^RAUTL22($P(ERR,U,2),IOM-7))
  1. . ;--- Display the additional information
  1. . I $G(RA8INFO)'="",$D(@RA8INFO)>1 S I="" D
  1. . . F S I=$O(@RA8INFO@(I)) Q:I="" D Q:RC<0
  1. . . . S RC=$$PAGE^RAUTL22 Q:RC<0
  1. . . . D W^RAUTL22(SP6_$$TRUNC^RAUTL22(@RA8INFO@(I),IOM-7))
  1. . Q:RC<0
  1. . ;--- Display the location
  1. . S I=$TR($P(ERR,U,3),"~","^")
  1. . I I'="" S RC=$$PAGE^RAUTL22 D:RC'<0 W^RAUTL22(SP6_I)
  1. Q:RC<0 RC
  1. ;===
  1. S RC=$$PAGE^RAUTL22
  1. Q $S(RC<0:RC,1:0)
  1. ;
  1. ;***** RETURNS THE ERROR STACK FROM A REMOTE PROCEDURE
  1. ;
  1. ; .RESULT Reference to a local variable where the error
  1. ; descriptors are returned to.
  1. ;
  1. ; LASTERR The last error code.
  1. ;
  1. ; Return Values:
  1. ;
  1. ; RESULT(0) Result descriptor
  1. ; ^01: The last error code (LASTERR)
  1. ; ^02: Number of error descriptors
  1. ;
  1. ; RESULT(i) Error descriptor
  1. ; ^01: Error code
  1. ; ^02: Message
  1. ; ^03: Error location
  1. ; RESULT(j) Line of the additional info
  1. ; ^01: ""
  1. ; ^02: Text
  1. ;
  1. ; Error descriptors are returned in reverse chronological order
  1. ; (most recent first).
  1. ;
  1. RPCSTK(RESULT,LASTERR) ;
  1. N CNT,ECNT,EPTR,I,TMP
  1. K RESULT S RESULT(0)=(+LASTERR)_U_"0"
  1. S TMP=$$RTRNFMT^XWBLIB(2,1)
  1. Q:$D(RAERROR("ES"))<10
  1. ;
  1. S EPTR="",(CNT,ECNT)=0
  1. F S EPTR=$O(RAERROR("ES",EPTR),-1) Q:EPTR="" D
  1. . S TMP=$G(RAERROR("ES",EPTR,0)) Q:'TMP
  1. . S CNT=CNT+1,ECNT=ECNT+1,RESULT(CNT)=TMP
  1. . S I=0
  1. . F S I=$O(RAERROR("ES",EPTR,1,I)) Q:I'>0 D
  1. . . S CNT=CNT+1,$P(RESULT(CNT),U,2)=RAERROR("ES",EPTR,1,I)
  1. ;
  1. S $P(RESULT(0),U,2)=ECNT
  1. K ^TMP("DILIST",$J)
  1. Q
  1. ;
  1. ;+++++ DEFAULT RUN-TIME ERROR HANDLER
  1. ;
  1. ; RAZZRCV Name of a variable that the error code
  1. ; (-1, -2, or -4) is assigned to.
  1. ;
  1. ; RAZZSTL Stack level (value of the $STACK special variable)
  1. ; where execution control is returned to.
  1. ;
  1. RTEHNDLR(RAZZRCV,RAZZSTL) ;
  1. N RAZZERR,RAZZRC
  1. S RAZZERR=$$EC^%ZOSV
  1. S:$ECODE=",UTIMEOUT," RAZZRC=-2
  1. S:$ECODE=",UCANCEL," RAZZRC=-1
  1. ;--- Record the error if this is not user "^" or timeout
  1. I '$G(RAZZRC) D ^%ZTER S RAZZRC=+$$ERROR^RAERR(-4,,RAZZERR)
  1. ;--- Unwind the stack and assign/return the error code
  1. S $ECODE="",RAZZSTL=RAZZSTL+1
  1. I RAZZSTL>0,$STACK(-1)>RAZZSTL D
  1. . S $ETRAP="S:$ESTACK'>0 $ECODE="""""
  1. . S:RAZZRCV'="" $ETRAP=$ETRAP_","_RAZZRCV_"="_RAZZRC
  1. . S $ETRAP=$ETRAP_" Q:$QUIT "_RAZZRC_" Q"
  1. . S $ECODE=",U1,"
  1. E S:RAZZRCV'="" @RAZZRCV=RAZZRC
  1. Q:$QUIT RAZZRC Q