9-3. Creating and Raising Named Programmer-Defined Exceptions

Problem

You want to alert the users of your application when a specific event occurs. The event does not raise an Oracle exception, but it is rather an application-specific exception. You want to associate this event with a custom exception so that it can be raised whenever the event occurs.

Solution

Declare a named user-defined exception, and associate it with the event for which you are interested in raising an exception. In the following example, a user-defined exception is declared and raised within a code block. When the exception is raised, the application control is passed to the statements contained within the exception handler for the named user exception.

CREATE OR REPLACE ...

Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.