$procerror

Return the reason for an error in Proc execution.

$procerror {=Value}

reset$procerror

Return Values

You can use the error constants in writing your Proc to make it more readable.

Use

Allowed in all Uniface component types.

Description

The $procerror function returns a value that indicates the reason for an Proc execution error. The following functions are also of use in this situation:

The function $procerror returns a value that indicates the reason for a Proc 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. The following functions are also of use in this situation:

  • $procerrorcontext to determine the location of the error in your Proc code.

  • $dataerrorcontext to determine the exact location of the error in the component's data structure.

The $procerror function is set to 0 at the start of any Proc 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 Proc code, $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 Proc code, $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:  Proc 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 Proc functions return an error in $procerror, even if the last Proc 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 ($status >= 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>)
   aksmess "Sorry, something's wrong."
else
   aksmess "Problem: %%$status / %%$procerror"
endif