$procerror

Return the reason for an error in ProcScript execution.

{Result = } $procerror

reset  $procerror

Return Values

$procerror returns a value that indicates the reason for a ProcScript execution error reported in $status. You can use the error constants in writing your ProcScript to make it more readable.

Use

Allowed in all component types.

Description

The function $procerror returns a value that indicates the reason for a ProcScript execution error reported in $status. When $status and $procerror are both negative, $status indicates that an error occurred and $procerror determines the reason for the error. This allows you to write error processing code.

For validation errors, the following functions are also of use:

  • $procerrorcontext to determine the location of the error in your ProcScript.
  • $dataerrorcontext to determine the exact location of a validation error in the component's data structure.

The $procerror function is set to 0 at the start of any ProcScript module (and with reset  $procerror). It is set to a negative value if an error occurs, as follows:

  • For a simple statement (such as creocc and putitem), $procerror is less than 0 and $status is usually less than 0.
  • For a statement that activates another module (such as activate or call), both $procerror and $status are less than 0. (If $status is set by ProcScript, $procerror remains 0.)
  • For a statement that causes ‘nested’ activation of triggers (such as store and validate), both $procerror and $status are less than 0. (If $status is set by ProcScript, $procerror is set to <UGENERR_4GL_SAYS_ERROR>. )
  • For a function, $procerror is less than 0 and $status is usually not changed.

If $procerror is set to Value, the description and mnemonic for this value can be retrieved from $procerrorcontext.

Note:  ProcScript functions only set $procerror in case of failure.; they do not reset $procerror to 0 in case of success. This behavior ensures that expressions that contain several ProcScript functions return an error in $procerror, even if the last ProcScript function was successful; $procerror holds the last error value.

Error Handling with $procerror

Symbolic error constant names can be used to create global constants. These can be used with $procerror to write generalized and more readable error handling routines. For example:

store
if ($procerror >= 0)
   done
elseif ($procerror = <UIOSERR_LOCKED>)
   askmess "This occurrence is in use elsewhere. Please try later."
elseif ($procerror = <UIOSERR_UPDATE_NOTALLOWED>)
   askmess "You don't have Write permission."
elseif ($procerror = <UGENERR_ERROR>)
   askmess "Sorry, something's wrong."
else
   askmess "Problem: %%$status / %%$procerror"
endif

Related Topics