Thanks for the question, shiva.
Asked: September 21, 2016 - 3:15 am UTC
Last updated: September 21, 2016 - 10:36 pm UTC
Version: 11g
Viewed 1000+ times
You Asked
Hi ,
I wanted to know is pragma exception init and raise_application_error does the same thing? I wanted to know what is the difference?
Also, I wanted to know what is the use , if I place my exception declaration in the package specification?
and Connor said...
"exception init" lets you associate your own named exception with an error number (any error number). For example, lets say I wanted to catch ORA-942 - there is no predefined exception in plsql for that, so I can build my own
SQL> begin
2 execute immediate 'drop table my_table';
3 end;
4 /
begin
*
ERROR at line 1:
ORA-00942: table or view does not exist
ORA-06512: at line 2
SQL>
SQL>
SQL>
SQL> declare
2 table_missing exception;
3 pragma exception_init(table_missing,-942);
4 begin
5 execute immediate 'drop table my_table';
6 exception
7 when table_missing then
8 null;
9 end;
10 /
PL/SQL procedure successfully completed.
Is this answer out of date? If it is, please let us know via a Comment