DEV Community

zuUwn21
zuUwn21

Posted on

# ๐Ÿ›ก๏ธ Uniface 10.4: Return Values & Error Handling with activate

๐Ÿ“Š Key Return Values

After calling an operation with activate, Uniface provides return values that help you assess the result and detect any errors.

$status โ€“ The Main Return Value

  • > 0: Successful execution, value returned by the operation.
  • 0: No value assigned or no return statement present.
  • < 0: An error occurred; details are in $procerror.
  • 9: User exited the form with ^ACCEPT.
  • 10: User exited the form with ^QUIT.

Code Example:

activate "MyCpt".do_it()
if ($status < 0)
    message "Error: " + $procerror
endif
Enter fullscreen mode Exit fullscreen mode

๐Ÿšจ Error Handling with $procerror

If an error occurs, $procerror contains a specific error code. The most important codes:

Error Code Meaning
-50 Component not found
-59 Operation not defined
-1122 Wrong number of arguments
-155 Instance could not be created
... See documentation for more

Code Example:

activate "MyCpt".do_it()
if ($status < 0)
    selectcase $procerror
        case -50
            message "Component not found!"
        case -59
            message "Operation does not exist!"
        case -1122
            message "Wrong number of arguments!"
        case else
            message "Unknown error: " + $procerror
    endselectcase
endif
Enter fullscreen mode Exit fullscreen mode

๐Ÿงฐ Best Practices

  • Always check $status and $procerror: Evaluate these values after every activate call.
  • Provide meaningful error messages: Use error codes to give targeted feedback.
  • Avoid negative return values: In your own operations, avoid returning negative values, as Uniface interprets them as errors.

๐Ÿ•ต๏ธโ€โ™‚๏ธ Common Pitfalls

  • Wrong arguments: Number or type does not match the operationโ€™s parameters.
  • Incorrect instance or operation name: Typos lead to -50 or -59.
  • Asynchronous calls: No OUT/INOUT parameters and no return value with /async.

๐Ÿ“ Example: Robust Error Handling

Code Example:

activate "MyService".calculate(100, 200)
if ($status < 0)
message "Error during call: " + $procerror
return
endif
message "Calculation successful! Result: " + $status
Enter fullscreen mode Exit fullscreen mode

This post is based on the official Uniface 10.4 documentation and was created with AI support. For details, see the original documentation.

Top comments (0)