Cartesius00
Cartesius00

Reputation: 24414

Exception handling out of stored procedure

In Oracle PL/SQL I need to write a stored procedure that may throw a custom exception and this exception must be caught (only this one) from some anonymous procedure calling this stored procedure. How to achieve that?

Upvotes: 1

Views: 1069

Answers (1)

APC
APC

Reputation: 146349

Custom exceptions (more often called "user defined exceptions") are easy enough to declare:

my_own_exception exception;

The main thing is that if you want to throw the specific exception in one procedure and catch in another you must declare the exception somewhere which is in scope for both programs. As you specify the calling (catching) procedure is an anonymous PL/SQL block that means you must declare the exception in a package spec: this can be the package which holds the called procedure or a package spec especially created to hold user-defined exceptions.

The PL/SQL documentation covers exceptions in some depth. Find out more.

Upvotes: 5

Related Questions