|
Oracle Error Handling - August 11, 2008 at 15:00 PM by Amit
Satpute
How PL/SQL Exceptions Are Raised?
Answer
The PL/SQL exceptions can be raised in 4 ways. Either the user can
raise them or they can be raised by the PL/SQL engine. They are as follows:
The PL/SQL runtime engine raised named system exception: These exceptions are
raised automatically by the program. You cannot control when PL/SQL will raise
a system exception.
The programmer raised named exception: The programmer can use an explicit call
to the RAISE statement to raise a programmer-defined or system-named exception.
The programmer raised unnamed, programmer-defined exception: These are raised
with an explicit call to the RAISE_APPLICATION_ERROR procedure in the
DBMS_STANDARD package.
The programmer re-raised "current" exception: From within an exception handler,
you can re-raise the same exception for propagation to the enclosing
block.
Explain the guidelines for Avoiding and Handling PL/SQL Errors and
Exceptions.
Answer
Guidelines for Avoiding and Handling PL/SQL Errors and
Exceptions
-
Use both error checking and exception handling to ensure your program can
handle all possibilities.
-
Add exception handlers whenever there is any possibility of an error
occurring.
-
Add error-checking code whenever you can predict that an error might occur if
your code gets bad input data.
-
Make your programs robust enough to work even if the database is not in the
state you expect.
-
Handle named exceptions whenever possible, instead of using WHEN OTHERS in
exception handlers.
-
Test your code with different combinations of bad data to see what potential
errors arise.
-
Write out debugging information in your exception handlers.
-
Carefully consider whether each exception handler should commit the
transaction, roll it back, or let it continue.
|