WORKING WITH EXCEPTIONS IN PL/SQL:
=================================
EXCEPTIONS:
a) It is an IDENTIFIER in PL/SQL, raised during the execution of a block that termination its main body of ACTIONS.
b) A block terminates when PL/SQL raises an EXCEPTION, By Specifying an Exception HANDLER we can perform final action.
METHODS TO RAISE AN EXCEPTION:
==============================
a) An ORACLE ERROR OCCURS and the associated exception is raised automatically.
b) Raise the EXCEPTION explicitly by issuing the RAISE statement within the Block.
c) The RAISED EXCEPTION can be either USER DEFINED or PREDEFINED.
EXCEPTION HANDLING:
==================
a) Exception Handling can happier in two ways
* Exception trapping
* Exception propagation
* EXCEPTION TRAPPING:
-------------------
-> If an Exception is raised in the Executable section of the Block then process the Exception to
the corresponding Exception Handling in the Exception Section of the same Block.
-> If the Exception is successfully handled then the exception should not propagate to the enclosing
block of environment.
-> If exception is trapped and Handled successfully then the PL/SQL Block terminated successfully.
* EXCEPTION PROPAGATION:
----------------------
-> If an EXCEPTION is raised in the executable section of the block and there is no corresponding
Exception Handler then the PL/SQL Block terminates with failure and the exception is
propagated to the calling encampment.
EXCEPTION TRAPPING EXCEPTION PROPAGATION
DECLARE DECLARE
BEGIN BEGIN
Exception Raised; Exception Raised;
EXCEPTION EXCEPTION
Exception Trapped; END
END
Exception Not Trapped
|
V
Exception Propagation to calling Environment.
TYPES OF EXCEPTIONS:
====================
a) As per PL/SQL Exception are considered to be of three types
* Predefined Oracle Server Errors
* Non-Predefined Oracle Server Errors
* User Defined Errors.
b) The PL/SQL programmer can program for exceptions to avoid disruption at Runtime.
SPECIFICATIONS OF EXCEPTIONS:
=============================
1) EXCEPTION TYPE : Predefined Oracle Server Errors
DESCRIPTION : These are one of appropriately 20 errors that occurs most often in PL/SQL code.
HANDLING TIP : Do not declare and allow the ORACLE SERVER to RAISE then Implicitly.
2) EXCEPTION TYPE : Non-Predefined Oracle Server Errors
DESCRIPTION : It is any other standard Oracle Server Error.
HANDLING TIP : Declare with in the Declarative Section and allow the Oracle Server to Raise them implicitly.
3) EXCEPTION TYPE : User Defined Errors
DESCRIPTION : It is any condition that the developer determines, which is abnormal.
HANDLING TIP : Declare with in the Declarative Section and Raise Explicitly.
TRAPPING EXCEPTIONS:
====================
a) Including a corresponding routine within the exception handling section of the PL/SQL block can trap any errors
raised while running a PL/SQL Block.
b) Each Exception Handler consists of WHEN clause which specifies an Exception.
c) Each Exception is followed by a sequence of statements to be executed when that exception is raised.
Syntax:
EXCEPTION
WHEN Exception 1[OR Exception 2.............]THEN
Statement 1;
Statement 2;
Statement 3;
.
.
.
.
WHEN OTHERS THEN
Statement 1;
Statement 2;
.
.
.
d) OTHERS is an optional EXCEPTION handling clause that traps unspecified Exceptions.
WHEN OTHERS EXCEPTION HANDLER:
==============================
a) The EXCEPTION Handling Section taps only those Exceptions that are specified any other Exceptions are not trapped
unless the OTHERS EXCEPTION handles is used.
b) The OTHERS should be the last exceptions handles in the defination.
TRAPPING EXCEPTIONS GUIDELINES:
===============================
a) Begin the exception handling section of the Block with the keyword EXCEPTION.
b) Define several Exception handlers, each with its own set of actions for the block.
c) When an Exception occurs PL/SQL processes only one handles before leaving the block.
d) Place the OTHERS clause after all other Exception Handling Clauses.
e) We can have at most one OTHERS clause.
f) EXCEPTIONS cannot appear in argument statements or SQL statements.
HANDLING PREDEFINED EXCEPTIONS:
===============================
a) A PREDEFINED Oracle Server Error Tapped by referencing its standard Name within the corresponding EXCEPTION
HANDLING Runtime.
b) All predefined Exceptions are declared by PL/SQL in the STANDARD Package.
SOME VERY COMMON PREDEFINED EXCEPTIONS:
EXCEPTION NAME NUMBER DESCRIPTION
ACCESS_INTO_NULL ORA_06530 Attempted to assign values to
the attributes of an instantiated object.
COLLECTION_IS_NULL ORA_06531 Attempt to apply collection methods other
than Exists to an uninitiated nested table
or VARY.
[8:22 PM
|
0
comments
]



0 comments
Post a Comment
Do comment to make this blog better