pragma exception [message #109387] |
Thu, 24 February 2005 05:15 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
SRM1
Messages: 13 Registered: February 2005 Location: Thane
|
Junior Member |
|
|
hi ,
what do u mean by pragma exception ?
how can one use it ?
thanks n regards,
-srm
|
|
|
Re: pragma exception [message #109398 is a reply to message #109387] |
Thu, 24 February 2005 06:28 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) |
![](/forum/images/custom_avatars/43055.jpg) |
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
From the docs:
Associating a PL/SQL Exception with a Number: Pragma EXCEPTION_INIT
To handle error conditions (typically ORA- messages) that have no predefined name, you must use the OTHERS handler or the pragma EXCEPTION_INIT. A pragma is a compiler directive that is processed at compile time, not at run time.
In PL/SQL, the pragma EXCEPTION_INIT tells the compiler to associate an exception name with an Oracle error number. That lets you refer to any internal exception by name and to write a specific handler for it. When you see an error stack, or sequence of error messages, the one on top is the one that you can trap and handle.
You code the pragma EXCEPTION_INIT in the declarative part of a PL/SQL block, subprogram, or package using the syntax
PRAGMA EXCEPTION_INIT(exception_name, -Oracle_error_number);
where exception_name is the name of a previously declared exception and the number is a negative value corresponding to an ORA- error number. The pragma must appear somewhere after the exception declaration in the same declarative section, as shown in the following example:
DECLARE
deadlock_detected EXCEPTION;
PRAGMA EXCEPTION_INIT(deadlock_detected, -60);
BEGIN
... -- Some operation that causes an ORA-00060 error
EXCEPTION
WHEN deadlock_detected THEN
-- handle the error
END;
|
|
|