Hi.
I have a procedure that throws a user defined exception that I want to handle in SQL*PLUS where the procedure is called. When the exception is thrown, I want a user message to the console and for SQL*PLUS to exit with a non-zero return code.
Currently getting "unhandled user-defined exception".
Can this be done? What am I doing wrong? Is there a better approach?
Thanks in advance, Nick.
=====================================
SQL> CREATE OR REPLACE PROCEDURE test1 (xxx IN NUMBER) IS
2 ex1 EXCEPTION;
3
4 BEGIN
5 IF xxx = 1 THEN
6 RAISE ex1;
7 END IF;
8
9 EXCEPTION
10 WHEN ex1 THEN
11 dbms_output.put_line('XXX=1');
12 RAISE;
13
14 END test1;
15 /
Procedure created.
SQL>
SQL>
SQL> whenever sqlerror exit failure
SQL> Declare
2 ex1 exception;
3 begin
4 test1(1);
5 exception
6 when ex1 then
7 RAISE;
8 end;
9 /
Declare
*
ERROR at line 1:
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "MMN.TEST1", line 12
ORA-06512: at line 4
I have a procedure that throws a user defined exception that I want to handle in SQL*PLUS where the procedure is called. When the exception is thrown, I want a user message to the console and for SQL*PLUS to exit with a non-zero return code.
Currently getting "unhandled user-defined exception".
Can this be done? What am I doing wrong? Is there a better approach?
Thanks in advance, Nick.
=====================================
SQL> CREATE OR REPLACE PROCEDURE test1 (xxx IN NUMBER) IS
2 ex1 EXCEPTION;
3
4 BEGIN
5 IF xxx = 1 THEN
6 RAISE ex1;
7 END IF;
8
9 EXCEPTION
10 WHEN ex1 THEN
11 dbms_output.put_line('XXX=1');
12 RAISE;
13
14 END test1;
15 /
Procedure created.
SQL>
SQL>
SQL> whenever sqlerror exit failure
SQL> Declare
2 ex1 exception;
3 begin
4 test1(1);
5 exception
6 when ex1 then
7 RAISE;
8 end;
9 /
Declare
*
ERROR at line 1:
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "MMN.TEST1", line 12
ORA-06512: at line 4