Classic Error Handling

If you do not use exception handling, you need to explicitly check $procerror for errors immediately after each relevant ProcScript instruction, and handle the error in some way.

For example:

trigger retrieve
  selectcase $procerror
   case 0 ; ok
   case -2, -4
     message/info "Retrieve: No data found in the database."
     message/error "Retrieve: Error occurred - (%%($procerror))."
  return 0

Uniface ProcScript instructions set $procerror to a negative value when something goes wrong while executing the instruction. Additional information about the error is provided in $procerrorcontext, and depending on the ProcScript instruction, in $procreturncontext or $dataerrorcontext.

If the error is not handled immediately after the relevant ProcScript command, it is ignored and code execution continues. A subsequent instruction may also result in an error, and set a different value for $procerror, so the original error information is lost. This makes it difficult to trace the origin of a problem back to the command that caused it.

You can write error handling code that deals with errors that are specific to a ProcScript command, as in the previous example. Or you can create a generic error handler that can be called after relevant ProcScript instructions. For example:

call getChild(vTargetUrl, vTargetObject)
  #include uError:handler  ; IncludeScript that deals with negative $procerror values
vPos = pTarget->position
  #include uError:handler

Other Uses of ProcScript Error

Sometimes, the value of $procerror can be used as exit condition in loops. For example:

setocc "MYENT", 1
while ($procerror != -1203)  ; no more occurrences
  $1 = $curocc("MYENT")
  setocc "MYENT", $curocc("MYENT") + 1

Related Topics