When building applications with Oracle Forms, one of the most important aspects of user interaction is how errors are communicated. By default, Oracle Forms displays system-generated error messages that are often technical and confusing for end users. To create a more user-friendly experience, you can replace these default messages with custom error messages that are clear, meaningful, and aligned with business rules.
This article explains why custom error messages are useful, different methods to implement them, and best practices for delivering effective communication in Oracle Forms.
Why Use Custom Error Messages?
System-generated messages may include technical terms, error codes, or database-related details that users cannot easily understand. For example, an error like ORA-00001: unique constraint violated does not explain what the user should do next.
By creating custom messages, you can:
- Simplify complex errors → Convert technical errors into plain language.
- Guide users to solutions → Tell users what they need to fix or enter.
- Maintain consistency → Provide a standard tone and style for messages.
- Improve user experience → Reduce frustration and training requirements.
Techniques to Create Custom Error Messages
Oracle Forms provides several ways to create and display custom messages. Let’s go through the most common methods.
1. Using the MESSAGE Built-in
The simplest way to display a custom message is by using the MESSAGE built-in.
Example:
IF :EMP.SALARY < 1000 THEN
MESSAGE('Salary must be greater than 1000.');
RAISE FORM_TRIGGER_FAILURE;
END IF;
This approach is useful for basic field validations.
2. Using the ON-ERROR Trigger
The ON-ERROR trigger allows you to intercept system errors and replace them with custom messages.
Example:
DECLARE
err_code NUMBER := ERROR_CODE;
BEGIN
IF err_code = 40508 THEN
MESSAGE('This field cannot be left blank.');
ELSE
MESSAGE('An unexpected error occurred. Please contact support.');
END IF;
RAISE FORM_TRIGGER_FAILURE;
END;
Here, error code 40508 is mapped to a friendly custom message for required fields.
3. Using the ON-MESSAGE Trigger
The ON-MESSAGE trigger is helpful for intercepting and customizing standard messages that Oracle Forms displays.
Example:
BEGIN
MESSAGE('Custom Message: ' || MESSAGE_TEXT);
RAISE FORM_TRIGGER_FAILURE;
END;
This ensures that even system messages are displayed in a controlled manner.
4. Using Alerts for Error Messages
Alerts provide a more visible way to display custom error messages compared to simple text messages.
Steps to use alerts:
- Create an alert object in the Forms Builder.
- Use the SHOW_ALERT built-in to display it.
Example:
DECLARE
al_id ALERT;
btn NUMBER;
BEGIN
al_id := FIND_ALERT('ERROR_ALERT');
SET_ALERT_PROPERTY(al_id, ALERT_MESSAGE_TEXT, 'Invalid Department ID. Please enter a valid one.');
btn := SHOW_ALERT(al_id);
RAISE FORM_TRIGGER_FAILURE;
END;
This method ensures users cannot miss the error message, making it suitable for critical issues.
5. Handling Business-Specific Validations
Custom error messages are especially important for business rule enforcement. For example:
IF :ORDERS.ORDER_DATE > SYSDATE THEN
MESSAGE('Order date cannot be in the future.');
RAISE FORM_TRIGGER_FAILURE;
END IF;
This not only prevents invalid data but also explains the reason clearly.
Best Practices for Custom Error Messages
To make your custom messages effective, follow these practices:
- Be clear and concise → Use simple language that anyone can understand.
- Be specific → Tell users exactly what went wrong and how to fix it.
- Use consistent formatting → Keep the style uniform across your application.
- Avoid exposing technical details → Don’t display raw Oracle error codes unless necessary.
- Leverage alerts for critical errors → Use pop-up alerts when user attention is crucial.
- Log errors internally → Store technical details in a log table for developers, while showing user-friendly messages to end users.
Conclusion
Creating custom error messages in Oracle Forms is essential for building applications that are both user-friendly and reliable. Whether through the MESSAGE built-in, ON-ERROR and ON-MESSAGE triggers, or alerts, you can ensure that users receive clear, actionable guidance instead of confusing system errors. By following best practices, you improve usability, reduce user frustration, and ensure smooth business operations.

