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

RAERR.m

Go to the documentation of this file.
  1. RAERR ;HCIOFO/SG - ERROR HANDLING ; 4/10/08 4:46pm
  1. ;;5.0;Radiology/Nuclear Medicine;**90**;Mar 16, 1998;Build 20
  1. ;
  1. ; * Error codes are negative numbers.
  1. ;
  1. ; * The corresponding error messages are stored in the DIALOG file
  1. ; (#.84). Dialog numbers are calculated as follows:
  1. ;
  1. ; Dialog# = 700000 - (ErrorCode / 1000).
  1. ;
  1. ; For example, dialog number for the error code -9 is 700000.009.
  1. ;
  1. ; * A message itself is stored in the second "^"-piece of the dialog
  1. ; text line. The first piece determines the problem type:
  1. ;
  1. ; I - Information. No actions are required.
  1. ;
  1. ; The $$ERROR^RAERR does not store this kind of messages in
  1. ; the RAERROR stack. However, they can be explicitly stored
  1. ; there using the PUSH^RAERR.
  1. ;
  1. ; W - Warning. There was a problem but the code was able to
  1. ; ignore/recover and continue. It would be a good idea
  1. ; to review the problem and fix it if/when possible.
  1. ;
  1. ; E - Error. The code encountered a major problem and could
  1. ; not continue. Data, code, or both should be fixed!
  1. ;
  1. Q
  1. ;
  1. ;***** INITIALIZES THE ERROR STACK
  1. ;
  1. ; [ENABLE] Enable error stack (0|1). If the stack is enabled,
  1. ; the $$ERROR function stores all error descriptors
  1. ; there. Otherwise, only the latest error descriptor
  1. ; is accessible (the result value of the $$ERROR
  1. ; function).
  1. ;
  1. CLEAR(ENABLE) ;
  1. S:$G(ENABLE)="" ENABLE=+$G(RAERROR("ES"))
  1. K RAERROR("ES") D:ENABLE ENABLE(1)
  1. D CLEAN^DILF
  1. Q
  1. ;
  1. ;***** CHECKS THE ERRORS AFTER A FILEMAN DBS CALL
  1. ;
  1. ; RA8MSG Closed reference of the error message array
  1. ; (from DBS calls). If this parameter is empty,
  1. ; then ^TMP("DIERR",$J) is assumed.
  1. ;
  1. ; [ERRCODE] Error code to assign (see dialogs #700000.*).
  1. ;
  1. ; [FILE] File number used in the DBS call.
  1. ; [IENS] IENS used in the DBS call.
  1. ;
  1. ; This function checks the DIERR and @RA8MSG variables for
  1. ; errors after a FileMan DBS call.
  1. ;
  1. ; Return Values:
  1. ;
  1. ; If there are no errors found, it returns an empty string.
  1. ; In case of errors, the result depends on value of the
  1. ; parameter:
  1. ;
  1. ; If ERRCODE is omitted or equals 0, the function returns a string
  1. ; containing the list of FileMan error codes separated by comma.
  1. ;
  1. ; If ERRCODE is not zero, the $$ERROR^RAERR function is called
  1. ; and its result is returned.
  1. ;
  1. ; NOTE: This entry point can also be called as a procedure:
  1. ; D DBS^RAERR(...) if you do not need its return value.
  1. ;
  1. DBS(RA8MSG,ERRCODE,FILE,IENS) ;
  1. I '$G(DIERR) Q:$QUIT "" Q
  1. N ERRLST,ERRNODE,I,MSGTEXT
  1. S ERRNODE=$S($G(RA8MSG)'="":$NA(@RA8MSG@("DIERR")),1:$NA(^TMP("DIERR",$J)))
  1. I $D(@ERRNODE)<10 Q:$QUIT "" Q
  1. ;--- Return a list of errors
  1. I '$G(ERRCODE) D Q:$QUIT $P(ERRLST,",",2,999) Q
  1. . S ERRLST="",I=0
  1. . F S I=$O(@ERRNODE@("E",I)) Q:'I S ERRLST=ERRLST_","_I
  1. . D CLEAN^DILF
  1. ;--- Record the error message
  1. D MSG^DIALOG("AE",.MSGTEXT,,,$G(RA8MSG)),CLEAN^DILF
  1. S I=$S($G(FILE):"; File #"_FILE,1:"")
  1. S:$G(IENS)'="" I=I_"; IENS: """_IENS_""""
  1. S I=$$ERROR(ERRCODE,.MSGTEXT,I)
  1. Q:$QUIT I Q
  1. ;
  1. ;***** ENABLES/DISABLES THE ERROR STACK
  1. ;
  1. ; ENABLE Enable (1) or disable (0) the error stack.
  1. ; Content of the stack is not affected.
  1. ;
  1. ; Return Values:
  1. ;
  1. ; Previous state of the stack: 1 - enabled, 0 - disabled.
  1. ;
  1. ; NOTE: This entry point can also be called as a procedure:
  1. ; D ENABLE^RAERR(...) if you do not need its return value.
  1. ;
  1. ENABLE(ENABLE) ;
  1. N OLD
  1. S OLD=+$G(RAERROR("ES"))
  1. S RAERROR("ES")=+ENABLE
  1. Q:$QUIT OLD Q
  1. ;
  1. ;***** GENERATES THE ERROR MESSAGE
  1. ;
  1. ; ERRCODE Error code (see dialogs #700000.*).
  1. ;
  1. ; [[.]RAINFO] Optional additional information: either a string or
  1. ; a reference to a local array that contains strings
  1. ; prepared for storing in a word processing field
  1. ; (first level nodes; no 0-nodes).
  1. ;
  1. ; [ARG1-ARG5] Optional parameters for $$MSG^RAERR01.
  1. ;
  1. ; Return Values:
  1. ; <0 Error code^Message text^Error location^Type
  1. ; 0 Ok (if ERRCODE'<0)
  1. ;
  1. ; NOTE: "^" is replaced with "~" in the error location stored
  1. ; in the 3rd piece of the error descriptor.
  1. ;
  1. ; NOTE: This entry point can also be called as a procedure:
  1. ; D ERROR^RAERR(...) if you do not need its return value.
  1. ;
  1. ERROR(ERRCODE,RAINFO,ARG1,ARG2,ARG3,ARG4,ARG5) ;
  1. I ERRCODE'<0 Q:$QUIT 0 Q
  1. N IEN,MSG,PLACE,SL,TMP,TYPE
  1. ;--- Get the error location
  1. S SL=$STACK(-1)-1,PLACE=""
  1. F Q:SL'>0 D Q:'(PLACE[$T(+0)) S SL=SL-1
  1. . S PLACE=$P($STACK(SL,"PLACE")," ")
  1. ;--- Prepare the additional information
  1. I $D(RAINFO)=1 S TMP=RAINFO K RAINFO S RAINFO(1)=TMP
  1. ;--- Prepare the message descriptor
  1. S MSG=$$MSG^RAERR01(ERRCODE,.TYPE,.ARG1,.ARG2,.ARG3,.ARG4,.ARG5)
  1. S MSG=(+ERRCODE)_U_MSG_U_$TR(PLACE,U,"~")_U_TYPE
  1. ;--- Store the descriptor
  1. D:TYPE'="I" PUSH(MSG,.RAINFO)
  1. ;--- Display the error if debug mode is on
  1. I $G(RAPARAMS("DEBUG"))>1 U $G(IO(0),0) D U $G(IO,0)
  1. . D PRTERRS^RAERR01(MSG,.RAINFO)
  1. ;---
  1. Q:$QUIT MSG Q
  1. ;
  1. ;***** GENERATES THE 'INVALID PARAMETER VALUE' ERROR
  1. ;
  1. ; RA8NAME Name of the parameter
  1. ;
  1. ; NOTE: This entry point can also be called as a procedure:
  1. ; D IPVE^RAERR(...) if you do not need its return value.
  1. ;
  1. IPVE(RA8NAME) ;
  1. N RA8RC
  1. S RA8RC=$S($D(@RA8NAME)#10:"'"_@RA8NAME_"'",1:"<UNDEFINED>")
  1. S RA8RC=$$ERROR(-3,RA8NAME_"="_RA8RC,RA8NAME)
  1. Q:$QUIT RA8RC Q
  1. ;
  1. ;***** PROCESSES THE ERROR DESCRIPTOR RETURNED BY $$LOCKFM^RALOCK
  1. ;
  1. ; ERROR Error descriptor
  1. ;
  1. ; OBJNAME Name of the object that the $$LOCKFM^RALOCK tried
  1. ; to lock when it returned the error descriptor.
  1. ;
  1. LOCKERR(ERROR,OBJNAME) ;
  1. Q $S(ERROR>0:$$ERROR(-15,$$TEXT^RALOCK(ERROR),OBJNAME),1:ERROR)
  1. ;
  1. ;***** PUSHES THE ERROR INTO THE ERROR STACK
  1. ;
  1. ; ERROR Error descriptor
  1. ;
  1. ; [.RAINFO] Reference to a local array with additional
  1. ; information
  1. ;
  1. PUSH(ERROR,RAINFO) ;
  1. Q:'$G(RAERROR("ES"))
  1. N IEN
  1. ;--- Store the descriptor
  1. S IEN=$O(RAERROR("ES"," "),-1)+1
  1. S RAERROR("ES",IEN,0)=ERROR
  1. M RAERROR("ES",IEN,1)=RAINFO
  1. Q
  1. ;
  1. ;***** ASSIGNS THE DEFAULT ERROR HANDLER
  1. ;
  1. ; [RCVNAME] Name of a variable for the error code
  1. ;
  1. ; See the RTEHNDLR^RAERR01 for more details.
  1. ;
  1. SETDEFEH(RCVNAME) ;
  1. S $ECODE="",$ETRAP="D RTEHNDLR^"_$NA(RAERR01($G(RCVNAME),$STACK(-1)-2))
  1. Q