⚡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

In Oracle APEX, errors raised using raise_application_error (-20001) often include technical codes that users don’t understand. Showing these raw messages can make the application confusing, especially for non-technical users.

In this blog, we will see how to create a custom error handling function to remove these codes and show simple, user-friendly messages instead. This helps improve clarity, keeps messages consistent, and enhances the overall user experience.

Step 1: 

First we need to write a PLSQL function to replace / remove the error codes in the error messages. Copy and create this PLSQL function below in your SQL terminal.
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: 

Now we need to configure the custom error handling to handle the errors raised in the application. To do so, go to the shared components and click on the Application Definition.

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;;

Step 5: 

Now save and run the page, you will see the button in the page and click on the button, the error message will be shown and the error codes will be removed.

🔥 Conclusion

Thus, in Oracle APEX, we can improve error messages by using a custom error handling function to remove technical codes from raise_application_error(-20001). This ensures users see clear and simple messages instead of confusing system errors. This approach is easy to implement, simple to maintain, and helps improve the overall user experience.

Comments

Popular posts from this blog

🔍 Extending Smart Search Filter for Multiple Regions

📌Track Active Tab switch in Region Display Selector without any plugins

💡 Designing Dynamic QuickPicks in Oracle APEX