You can include an exception section within the BEGIN
block. The exception section begins with the keyword, EXCEPTION
, and continues until the end of the block in which it appears. If an exception is thrown by a statement within the block, program control goes to the exception section where the thrown exception may or may not be handled depending upon the exception and the contents of the exception section.
WHEN exception_condition THEN
declarations are one or more variable, cursor, type, or subprogram declarations that are local to the block. If subprogram declarations are included, they must be declared after all other variable, cursor, and type declarations. Each declaration must be terminated by a semicolon. The use of the keyword DECLARE depends upon the context in which the block appears.
statements are one or more SPL statements. Each statement must be terminated by a semicolon. The end of the block denoted by the keyword END
must also be terminated by a semicolon.
If present, the keyword EXCEPTION
marks the beginning of the exception section. exception_condition
is a conditional expression testing for one or more types of exceptions. If a thrown exception matches one of the exceptions in exception_condition
, the statements
following the WHEN exception_condition
clause are executed. There may be one or more WHEN exception_condition
clauses, each followed by statements
block in itself, is considered a statement; thus, blocks may be nested. The exception section may also contain nested blocks.