24. 14. 1. Exceptions |
|
In PL/SQL, the user can catch certain runtime errors. |
Exceptions can be internally defined by Oracle or the user. |
Exceptions are used to handle errors that occur in your PL/SQL code. |
A PL/SQL block contains an EXCEPTION block to handle exception. |
There are three types of exceptions: |
- Predefined Oracle errors
- Undefined Oracle errors
- User-defined errors
|
The different parts of the exception. |
- Declare the exception.
- Raise an exception.
- Handle the exception.
|
An exception has four attributes: |
- Name provides a short description of the problem.
- Type identifies the area of the error.
- Exception Code gives a numeric representation of the exception.
- Error message provides additional information about the exception.
|
The predefined divide-by-zero exception has the following values for the attributes: |
- Name = ZERO_DIVIDE
- Type = ORA (from the Oracle engine)
- Exception Code = C01476
- Error message = divisor is equal to zero
|
The following is the typical syntax of an exception-handling PL/SQL block. |
exception
when exception_1 THEN
statements
when exception_2 THEN
statements
...
|
|
exception_1 and exception_2 are the names of the predefined exceptions. |
statements is the PL/SQL code that will be executed if the exception name is satisfied. |