β οΈ 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)