Handling Exceptions-Lectureslides
Handling Exceptions-Lectureslides
code in PL/SQL
•Describe the purpose of an EXCEPTION section in a PL/SQL block
•Create PL/SQL code to include an EXCEPTION section
•List several guidelines for exception handling
What is an Exception?
An exception occurs when an error is discovered during the
execution of a program that disrupts the normal operation of the
program.
There are many possible causes of exceptions: a user makes a
spelling mistake while typing; a program does not work correctly;
an advertised web page does not exist; and so on.
Can you think of errors that you have come across while using a
web site or application?
Exceptions in PL/SQL
This example works fine. But what if you entered ‘Korea, South’
instead of ‘Republic of Korea’?
Exceptions in PL/SQL (continued)
The code does not work as expected. No data was found for Korea, South
because the country name is actually stored as Republic of Korea.
This type of error in PL/SQL is called an exception. When code does not
work as expected, PL/SQL raises an exception. When an exception is
raised, the rest of the execution section of the PL/SQL block is not
executed.
What Is an Exception Handler?
An exception handler is code that defines the recovery actions to
be performed when an exception is raised (that is, when an error
occurs).
When writing code, programmers need to expect the types of
errors that can occur during the execution of that code. They need
to include exception handlers in their code to address these errors.
Exception handlers allow programmers to "bulletproof" their code.
What types of errors might programmers want to account for by
using an exception handler?
•System errors (for example, a hard disk is full)
•Data errors (for example, trying to duplicate a primary key
value)
•User action errors (for example, data entry error)
•Many other possibilities!
Why is Exception Handling Important?
• Protects the user from errors (Frequent errors can frustrate the
user and/or cause the user to quit the application.)
Neither Data not found exception nor too many rows exception are
occurred,
if some other exception is raised, then the statements in the OTHERS
exception handler are executed.
• Exception
• Exception handler
• Describe several advantages of including exception handling code
in PL/SQL