If you are required to standardize the exception handling, not just to control
the abnormal program flow but also to alter the program execution logic, you
need to use user-defined exceptions. The user-defined exceptions are raised in the
BEGIN..END section of the block using the RAISE statement.
With custom exceptions, Oracle allows users to specify names, associate error codes, and raise statements in line with the implementation logic.
There are three ways to declare user-defined exceptions.
-
EXCEPTION type variable:
-
Declare the
EXCEPTIONtype variable in the declaration section. -
Raise it explicitly in the program body using the
RAISEstatement. -
Handle it in the
EXCEPTIONsection. No error code will be involved here.
-
Declare the
-
EXCEPTION variable:
Declare theEXCEPTIONvariable and associate it with a standard error number usingPRAGMA EXCEPTION_INIT. -
RAISE_APPLICATION_ERROR:
Use theRAISE_APPLICATION_ERRORto declare a dedicated error number and error message.
No comments:
Post a Comment