We are developing a new module for our Insurance system. It has Oracle forms 11g as the front end, 11g R2 as the back-end DB.
I am trying to make the error handling as simple as possible using the KISS principle.
I created 3 SPs to simulate this:
create or replace
procedure sub_proc is
i number := 1;
BEGIN
DBMS_OUTPUT.PUT_LINE('SUB_PROC. About to raise 1/0 exception');
i := i / 0;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('----Exception Handler in SUB_PROC----');
RAISE_APPLICATION_ERROR(-20000, SQLERRM);
END;
create or replace
procedure top_level_proc is
-- This proc is called by the Oracle Form
BEGIN
DBMS_OUTPUT.PUT_LINE('top_level_proc');
SUB_PROC();
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('----Exception Handler in TOP_LEVEL_PROC----');
RAISE_APPLICATION_ERROR(-20000, SQLERRM);
END;
create or replace
procedure oracle_form is
-- This mimiks the Oracle Form front end
BEGIN
DBMS_OUTPUT.PUT_LINE('oracle_form');
top_level_proc();
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ORACLE_FORM EXCEPTION HANDLER: ' || SQLCODE || ' / ' || SQLERRM);
END;
Now I run the Form (simulation):
BEGIN
oracle_form();
END;
This is the output I get:
oracle_form
top_level_proc
SUB_PROC. About to raise 1/0 exception
----Exception Handler in SUB_PROC----
----Exception Handler in TOP_LEVEL_PROC----
ORACLE_FORM EXCEPTION HANDLER: -20000 / ORA-20000: ORA-20000: ORA-01476: divisor is equal to zero
As you can see, the Oracle Form's exception block, the exception I get is not clean.
In the Oracle Form's exception handler, I want to pop-up a small form
to give the user a nice small screen saying an error occurred and
also giving the error message, in this case ORA-01476: divisor is equal to zero.
Now, SQLERRM has this string: ORA-20000: ORA-20000: ORA-01476: divisor is equal to zero
How can we get only the ORA-01476: divisor is equal to zero as error?
Because, now I will have to process this string, staring with the end, and move forward
until I encounter the ORA-01476 and then get the sub-string. I might be even
able to do this using a regular expression, which I am not familiar with.
So, how to do this error handling elegantly?