Link to home
Start Free TrialLog in
Avatar of diteps06
diteps06Flag for United States of America

asked on

Centralised error management in PL/SQL

I have a number of packages that control EXCEPTIONS the same the way.
The instructions in the EXCEPTION section are
EXCEPTION
    WHEN NO_DATA_FOUND THEN
….
    WHEN DUP_VAL_ON_INDEX THEN
---
    WHEN OTHERS THEN
        ---
There is a global package which contain the definition of constants use in the various packages. I would like to define a procedure or function in this package that handles all the exception. Instead of writing the same code I would just need to call it.
How can it be done.
 Thanks in advance
Avatar of Sean Stuber
Sean Stuber

PROCEDURE handle_exception(p_sqlcode IN PLS_INTEGER default SQLCODE)
IS
BEGIN
    CASE p_sqlcode
        WHEN c_some_constant
        THEN
            NULL;                                                               -- fill in code here
        WHEN c_other_constant
        THEN
            NULL;                                                               -- fill in code here
        WHEN c_yet_another_constant
        THEN
            NULL;                                                               -- fill in code here
        ELSE
            NULL;                                              -- this will act as the "WHEN OTHERS"
    END CASE;
END;

then in  in your other procedures


EXCEPTION WHEN OTHERS THEN handle_exception;

ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you might want to look into dbms_utility package for error stack and back trace functions  to pull additional information about the error