Pl/sql handles exceptions differently from other programming languages, the PL/SQL exception handling mechanism is similar to Ada, with a full inclusion method for handling errors. When an error occurs, the program unconditionally transfers to the exception-handling section, which requires the code to be very clean and separate the error-handling part from the rest of the program. Oracle allows other exception condition types to be declared to extend error/exception handling. This extension makes Pl/sql exception handling very flexible.
When a run-time error occurs, it is called an exception thrown. Pl/sql Program compile-time error is not able to be handled abnormally, only at Run-time the exception can be handled. It is very important to throw and process the exception in Pl/sql programming.
Throw an exception
Throws an exception in three different ways
. Run-time engine via Pl/sql
. Using the Raise statement
. Calling Raise_application_error stored Procedures
When a database or Pl/sql error occurs at run time, an exception is thrown automatically by the Pl/sql runtime engine. Exceptions can also be thrown by raise statements
RAISE Exception_name;
An explicit throw exception is a idiom for programmers to handle declared exceptions, but raise is not limited to declared exceptions, and it can throw any exception. For example, if you want to detect a new Run-time exception handler with a Timeout_on_resource error, you simply use the following statement in your program:
RAISE Timeout_on_resouce;