PL/SQL Exceptions  «Prev  Next»

Lesson 6Raise explicit exceptions
Objective Raise an exception based on user-defined criteria.

Raise Explicit PL/SQL Exceptions

Exceptions can be raised implicitly at runtime by PL/SQL. Alternatively, PL/SQL provides you with the ability to call an exception explicitly with the RAISE statement.
User-defined PL/SQL exceptions must be:
  1. Declared within the DECLARE section of a PL/SQL block
  2. Raised explicitly with the RAISE statement

User-defined error
User-defined error

Ideally, a PL/SQL block should raise an exception only when an error makes it impossible or impractical to finish processing. A RAISE statement for a given expression can be coded anywhere within the scope of that expression. The RAISE statement stops normal execution of the PL/SQL block and transfers control to the appropriate exception handler. The exception can be a predefined exception or a user-defined exception.
RAISE statement
RAISE statement

Note: RAISE statement can also be used without an exception name. This is allowed only within an exception handler, and its effect is to reraise the current exception.
In the next lesson, you will learn about the use of functions and procedures within error handling.

Raise Explicit Exceptions - Exercise

Click the Exercise link below to match the different types of errors with their respective descriptions.
Raise Explicit Exceptions - Exercise