DEV Community

Peter + AI
Peter + AI

Posted on

πŸ” Understanding the $error Function in Uniface 10.4 ProcScript

⚠️ This blog post was created with AI assistance to help developers understand Uniface concepts better.

If you're working with Uniface applications, you've probably encountered errors during data input validation. The $error function is a powerful tool that helps you handle these situations gracefully. Let me break down what this function does and how you can use it effectively! πŸš€

πŸ€” What is $error?

The $error function is a built-in ProcScript function that returns the Uniface message number for the current error. Think of it as your error detective - it tells you exactly what went wrong by giving you a specific error code number.

πŸ“‹ Key Facts:

  • βœ… Returns a numeric error code
  • ⚠️ Can only be used inside error triggers
  • πŸ—οΈ Works with all component types
  • 🎯 Helps identify specific field or entity data input errors

πŸ› οΈ How to Use $error

The beauty of $error lies in its simplicity. When a data input error occurs, you can check the specific error code and decide how to handle it. This means you can provide different responses for different types of errors!

πŸ’‘ Real-World Example

Here's a practical example that shows how to handle an incorrect code error:


trigger error
variables
 vSelectedCode
endvariables

if ($error = 0126)  ; Error code 0126 = incorrect code
 message "Incorrect code. Select one from list."
 activate "CODES".exec(vSelectedCode) ; Show code selection form

 if ($status = 1)  ; User selected a valid code
  TYPECD = vSelectedCode  ; Apply the selected code
  return (0)  ; Continue processing
 else
  message "No code selected."
  return (-1)  ; Stop processing
 endif
else
 message $text("%%$error")  ; Show default error message
 return (-1)  ; Stop processing
endif

end; trigger
Enter fullscreen mode Exit fullscreen mode

🎯 Breaking Down the Example

Let's understand what happens in this code step by step:

  1. Error Detection πŸ”: The code checks if the error number is 0126 (incorrect code error)
  2. User-Friendly Response πŸ’¬: Instead of showing a cryptic error, it displays a helpful message
  3. Interactive Solution πŸ–±οΈ: It opens a form where users can select from valid codes
  4. Smart Recovery ✨: If the user picks a code, it automatically applies it and continues
  5. Fallback Handling πŸ›‘οΈ: For other errors, it shows the standard Uniface error message

πŸš€ Why This Approach is Powerful

This error handling pattern is excellent because:

  • User Experience 😊: Users get helpful guidance instead of confusing error codes
  • Productivity ⚑: Users can fix errors quickly without guessing
  • Flexibility πŸ”§: Different error codes can have different handling strategies
  • Professional Feel πŸ’Ό: Your application feels polished and well-thought-out

πŸŽͺ Best Practices

When working with $error, keep these tips in mind:

  • 🎯 Be Specific: Handle common error codes with tailored solutions
  • πŸ”„ Provide Alternatives: Give users ways to fix the problem
  • πŸ“ Keep Messages Clear: Use simple, actionable language
  • πŸ›‘οΈ Always Have a Fallback: Handle unexpected errors gracefully

🏁 Conclusion

The $error function might seem simple, but it's a cornerstone of good error handling in Uniface applications. By using it effectively, you can transform frustrating error situations into smooth, guided user experiences. 🌟

Remember: good error handling is not just about catching problems - it's about helping users solve them! πŸ’ͺ


Keywords: uniface, procscript, errorhandling, debugging

Top comments (0)