IBM AS/400 manual ILE Condition Handlers, Register the handler and generate errors

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 267
Image 267

ILE Condition Handlers

*

-----------------------------------------------------------------

 

 

 

*

 

 

 

 

 

* Register the handler and generate errors

 

*

*

-----------------------------------------------------------------

 

 

 

*

C

 

EXSR

RegHndlr

 

 

 

*

-----------------------------------------------------------------

 

 

 

*

*

Generate a substring error

 

 

*

*

This is an "allowed" error for this example (RPGHDLR

 

*

*

handles the exception, allowing control to return to the

*

*

next instruction after the error).

 

*

*

RPGHDLR will not allow the error unless the "AllowError"

*

*

indicator is set on.

This ensures that if, for example,

*

*

a SCAN operation is added to SHOWERR later, RPGHDLR will

*

*

not by default allow it to have an error.

 

*

*

-----------------------------------------------------------------

 

 

 

*

C

 

Z-ADD

-1

Num

 

 

C

 

EVAL

AllowError = '1'

 

 

C

Num

SUBST

'Hello'

Examp

10

 

C

 

EVAL

AllowError = '0'

 

 

*

-----------------------------------------------------------------

 

 

 

*

*

The exception was handled by the handler and control

 

*

*

resumes here.

 

 

 

*

*

-----------------------------------------------------------------

 

 

 

*

C

 

EXCEPT

ImBack

 

 

 

*

-----------------------------------------------------------------

 

 

 

*

*

Generate an array out of bounds error

 

*

*

This is not an "expected" error for this example.

 

*

*

-----------------------------------------------------------------

 

 

 

*

C

 

Z-ADD

-1

Num

 

 

C

 

MOVE

Arr1(Num)

Arr1(Num)

 

 

*

-----------------------------------------------------------------

 

 

 

*

*

The exception was not handled by the handler, so,

 

*

*

control does not return here.

The exception is

 

*

*

percolated and control resumes in the *PSSR.

 

*

*

-----------------------------------------------------------------

 

 

 

*

*

-----------------------------------------------------------------

 

 

 

*

*

Deregister the handler

 

 

 

*

*

Note: If an exception occurs before the handler is

 

*

*

deregistered, it will be automatically deregistered

 

*

*

when the procedure is cancelled.

 

*

*

-----------------------------------------------------------------

 

 

 

*

C

 

EXSR

DeRegHndlr

 

 

C

 

SETON

 

 

 

LR

*=================================================================*

* RegHdlr - Call the API to register the Handler

 

*

*=================================================================*

C

RegHndlr

BEGSR

 

 

 

 

C

 

CALLP

CEEHDLR(pConHdlr : %ADDR(CommArea) : *OMIT)

C

 

ENDSR

 

 

 

 

*=================================================================*

* DeRegHndlr - Call the API to unregister the Handler

 

*

*=================================================================*

C

DeRegHndlr

BEGSR

 

 

 

 

C

 

CALLP

CEEHDLU(pConHdlr : *OMIT)

 

 

C

 

ENDSR

 

 

 

 

 

 

 

 

Figure

117 (Part 2

of 3).

Source for Registering a Condition Handler

Chapter 12. Handling Exceptions243

Page 267
Image 267
IBM AS/400 manual ILE Condition Handlers, Register the handler and generate errors