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:
1. Predefined Oracle errors
2. Undefined Oracle errors
3. User-defined errors
The different parts of the exception.
1. Declare the exception.
2. Raise an exception.
3. Handle the exception.
An exception has four attributes:
1. Name provides a short description of the problem.
2. Type identifies the area of the error.
3. Exception Code gives a numeric representation of the exception.
4. Error message provides additional information about the exception.
The predefined divide-by-zero exception has the following values for the attributes:
1. Name = ZERO_DIVIDE
2. Type = ORA (from the Oracle engine)
3. Exception Code = C01476
4. Error message = divisor is equal to zero
Error Code Prefix Indicates This Exception Type of Error
ORA Core RDBMS errors
PLS PL/SQL errors
FRM Oracle Forms errors
REP Oracle Reports errors
WHEN OTHER en sonda bulunmalı çünkü bu exception mantığına aykırı bütün excaptınları kapsıyor. bunu önce yazdıgınızda diğerleri çalişmayacaktır. Bir örnek gösterelim.
BEGIN
2 DBMS_OUTPUT.PUT_LINE(1 / 0);
3 EXCEPTION
4 WHEN OTHERS THEN
5 DBMS_OUTPUT.PUT_LINE('An exception occurred');
6 WHEN ZERO_DIVIDE THEN
7 DBMS_OUTPUT.PUT_LINE('Division by zero');
8 END;
9 /
WHEN OTHERS THEN
*
ERROR at line 4:
ORA-06550: line 4, column 4:
PLS-00370: OTHERS handler must be last among the exception handlers of a block
ORA-06550: line 0, column 0:
PL/SQL: Compilation unit analysis terminated
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment