PL/SQL Exceptions  «Prev  Next»

Lesson 5 Implicit user-defined exceptions
Objective Use an implicit user-defined exception.

Implicit user-defined Exceptions

In Oracle, hundreds of standard system exceptions, such as ZERO_DIVIDE, are referenced by name. These are known as predefined server errors. You learned about them in the previous lesson. Internally, Oracle handles these messages by their error codes.
Implicit user-defined exceptions
Implicit user-defined exceptions

Exception Flag

Messages that are not named raise an exception flag, and the control transfers to the EXCEPTION block. These are referred to as non-predefined server errors. All such messages are caught by the OTHERS exception handler. You can provide names to such messages using the PRAGMA EXCEPTION_INIT command.
PRAGMA stands for pseudo instructions. It is the keyword that signifies that the statement is a compiler directive, which is not processed when the PL/SQL block is executed. Rather, it directs the PL/SQL compiler to interpret all occurrences of the exception name within the block as the associated Oracle server error number.
The following MouseOver best explains how to code these kinds of exceptions.
Implicit user-defined exceptions
  1. exception_error_occurred - A name to the exception error that needs to be trapped
  2. An integer value denoting the exception error code
  3. statement_1,...,statement_n - A sequence of statements
  4. statement_11,...,statement_n - A sequence of statements
  5. e_pet_care_log_remaining EXCEPTION - Declaring and naming the exception
  6. PRAGMA EXCEPTION_INIT (e_pet_care_log_remaining, -2292) - Linking the integrity constraint violation to e_pet_care_log_remaining
  7. WHEN e_pet_care_log_remaining THEN - Providing the error handling routine

Implicit user Defined Exceptions

Implicit User Defined Exceptions - Exercise

Click the Exercise link below to rearrange the code for a PL/SQL block that handles exceptions.
Implicit User Defined Exceptions - Exercise
In the next lesson, you will learn how to raise explicit exceptions.