⚡Simplify APEX Error Notifications with a Custom Error Handler
🚩Introduction
In modern Oracle APEX applications, it is important to show clear and simple error messages so users can understand them easily. By default, the errors raised using raise_application_error(-20001) may include technical codes that can confuse users.
To improve this, we can use a custom error handling function that hides these codes and shows clean, meaningful messages instead. This makes the application easier to understand, improves usability, and gives a better user experience.
📑 Why This Approach Is Needed
In Oracle APEX applications, default error messages from raise_application_error(-20001) often show technical codes that users does not understand. These messages can be confusing and not very user-friendly, especially in business applications where clear communication is important.
Customizing error handling becomes important when:
- Users should see clear, human-readable error messages
Technical error codes need to be hidden from the interface
Error messages must be consistent across the application
Developers want better control over how exceptions are displayed
Applications aim to provide a clean and professional user experience
This approach ensures better readability, improved usability, and a more polished application by presenting only relevant and meaningful error information to users.
👉 Use Case: Custom Error Handling in Oracle APEX
Step 1:
CREATE OR REPLACE FUNCTION custom_error_handler_f (
p_error IN apex_error.t_error
)
RETURN apex_error.t_error_result
IS
l_result apex_error.t_error_result;
BEGIN
l_result := apex_error.init_error_result(p_error);
IF p_error.ora_sqlcode = -20001 THEN
------ replace error code ------
l_result.message := REPLACE(p_error.message, 'ORA-20001: ', '');
l_result.display_location := apex_error.c_inline_in_notification;
END IF;
RETURN l_result;
END;
Step 2:
Step 3:
In the Application Definition page, scroll and navigate to the Error handling section. You need to enter the function name which you created in the previous step in the Error Handling Function property.
Step 4:
Now, whenever an error is raised in the application, this custom error handling will be executed and this will remove the error codes and displays only the error messages. To check this create one button in the page and create one procees, In that copy and paste the below mesasage.
BEGIN
RAISE_APPLICATION_ERROR(-20001, 'Raise Error'); -- raise a user defined error
END;;





Comments
Post a Comment