Using Exception Handlers In Procedures - Sybase Adaptive Server IQ 12.4.2 Administration And Performance Manual

Table of Contents

Advertisement

Using exception handlers in procedures

Drop the procedures
The procedures both continued executing after the warning was generated,
with SQLSTATE set by the warning (02000).
It is often desirable to intercept certain types of errors and handle them within
a procedure, rather than pass the error back to the calling environment. This is
done through the use of an exception handler.
An exception handler is defined with the EXCEPTION part of a compound
statement (see "Using compound statements" on page 240). The exception
handler is executed whenever an error occurs in the compound statement.
Unlike errors, warnings do not cause exception handling code to be executed.
Exception handling code is also executed if an error is encountered in a nested
compound statement or in a procedure that has been invoked anywhere within
the compound statement.
Remember to drop both the
continuing with the tutorial. You can do this by entering the following
commands in the command window:
DROP PROCEDURE OUTERPROC;
DROP PROCEDURE INNERPROC
The demonstration procedures used to illustrate exception handling are based
on those used in "Default error handling in procedures" on page 256 In this
case, additional code is added to handle the
procedure.
InnerProc
CREATE PROCEDURE OuterProc()
BEGIN
MESSAGE 'Hello from OuterProc.';
CALL InnerProc();
MESSAGE 'SQLSTATE set to ',
SQLSTATE,' in OuterProc.'
END
CREATE PROCEDURE InnerProc()
BEGIN
DECLARE column_not_found
EXCEPTION FOR SQLSTATE '52003';
MESSAGE 'Hello from InnerProc.';
SIGNAL column_not_found;
MESSAGE 'Line following SIGNAL.';
EXCEPTION
WHEN column_not_found THEN
CHAPTER 6
Using Procedures and Batches
and
InnerProc
OuterProc
column not found
procedures before
error in the
261

Advertisement

Table of Contents
loading

Table of Contents