简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM