Error handling with on exception resume – Sybase 12.4.2 User Manual

Page 278

Advertising
background image

Errors and warnings in procedures

258

Error handling with ON EXCEPTION RESUME

If the ON EXCEPTION RESUME clause is included in the CREATE
PROCEDURE statement, the procedure checks the following statement when
an error occurs. If the statement handles the error, then the procedure does not
return control to the calling environment when an error occurs. Instead, it
continues executing, resuming at the statement after the one causing the error.

Note

When a statement has several parts or clauses, such as IF, ELSE IF, END

IF, or FOR and END FOR, the “following statement” refers to the next new
statement, not a statement part.

The following statements are considered error-handling statements:

IF

SELECT @variable =

CASE

LOOP

LEAVE

CONTINUE

CALL

EXECUTE

SIGNAL

RESIGNAL

DECLARE

The following example illustrates how this works.

Drop the procedures

Remember to drop both the

InnerProc

and

OuterProc

procedures before

continuing with the tutorial. You can do this by entering the following
commands in the command window:

DROP PROCEDURE OUTERPROC;

DROP PROCEDURE INNERPROC

The following demonstration procedures show what happens when an
application calls the procedure

OuterProc

; and

OuterProc

in turn calls the

procedure

InnerProc

, which then encounters an error. These demonstration

procedures are based on those used earlier in this section:

Advertising