⚠️ 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
🎯 Breaking Down the Example
Let's understand what happens in this code step by step:
- Error Detection 🔍: The code checks if the error number is 0126 (incorrect code error)
- User-Friendly Response 💬: Instead of showing a cryptic error, it displays a helpful message
- Interactive Solution 🖱️: It opens a form where users can select from valid codes
- Smart Recovery ✨: If the user picks a code, it automatically applies it and continues
- 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)