A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

32
A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer

Transcript of A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

Page 1: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

A5: Structured Error Handling in the ABL

Phillip MaloneSenior Technical Support Engineer

Page 2: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation2

Structured Error Handling -- Agenda

Overview of the old and new Catching errors Raising errors The FINALLY block Changes to be aware of

Page 3: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation3

NO-ERROR / ERROR-STATUS

Traditional Error Handling Model

Behavior handled at the statement level

ON ERROR, UNDO { LEAVE | RETRY | …}

Behavior handled locally at the block level

RETURN ERROR [error string]

Application can return error to its caller

Page 4: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation4

Failure cases handled in varied and inconsistent ways

Errors must be handled locally, do not propagate automatically

No way to add additional information to application errors

Traditional Error Handling Model

Page 5: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation5

A Bit About Blocks

Page 6: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation6

UNDO,ON ERROR

RETRYNEXTLEAVERETURN

A Bit About Blocks

Outer Block

Inner Block

Page 7: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation7

UNDO,ON ERROR

RETRYNEXTLEAVERETURN

A Bit About Blocks

Outer Block

Inner Block

E

Page 8: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation8

CATCH err AS Progress.Lang.Error

Structured Error Handling Model – 10.1C

CATCH blocks to handle all error types

myError INHERITS Progress.Lang.AppError

Ability to create user-defined application errors

Facilities to propagate errors up the call stack

UNDO, THROW <error object>

Page 9: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation9

Let’s look at the code

PROCEDURE ErrorBlock:

FOR EACH Customer ON ERROR UNDO, LEAVE: FIND FIRST Order WHERE Order-Num = 1001 NO-ERROR. IF ERROR-STATUS:ERROR THEN

MESSAGE ERROR-STATUS:GET-MESSAGE(1).

FIND FIRST Order WHERE Order-Num = 1002. END.

END PROCEDURE.

Page 10: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation10

ON ERROR UNDO,

RETRYNEXT LEAVERETURN

Catching Errors

Enclosing Block

Associated Block

Catch E

Page 11: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation11

Let’s look at the code

PROCEDURE ErrorBlock:

FOR EACH Customer: FIND FIRST Order WHERE Order-Num = 1001. CATCH e AS Progress.Lang.SysError: MESSAGE e:GetMessage(1) VIEW-AS ALERT-BOX. DELETE OBJECT e. END CATCH. END.

END PROCEDURE.

Page 12: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation12

Object Hierarchy

Progress.Lang.Object

Progress.Lang.ProError

Progress.Lang.AppError Progress.Lang.SysError

Progress.Lang.

SoapFaultError

User-Defined

Error Objects

Progress.Lang.Error

<<interface>>

Page 13: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation13

Error Objects

NumMessages, Severity, CallStack

Properties available on ProError

GetMessage(), GetMessageNum()

Methods available on ProError

AddMessage(), RemoveMessage()

ReturnValue

Additional Methods and Properties on AppError

Page 14: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation14

ON ERROR UNDO,

RETRYLEAVENEXTRETURN

Throwing Errors

Enclosing Block

Associated Block

E

THROW

Page 15: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation15

Throwing Errors

ROUTINE-LEVEL ON ERROR UNDO, THROW

Overrides default ON ERROR of routine level blocks

UNDO, THROW <error object>

Explicitly throws (or re-throws) an error

Page 16: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation16

Let’s look at the code

PROCEDURE ErrorBlock:

FOR EACH Customer ON ERROR UNDO, LEAVE: FIND FIRST Order WHERE Order-Num = 1001 NO-ERROR. IF ERROR-STATUS:ERROR THEN

MESSAGE ERROR-STATUS:GET-MESSAGE(1).

END.

END PROCEDURE.

Page 17: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation17

Let’s look at the code

ROUTINE-LEVEL ON ERROR UNDO, THROW.

PROCEDURE ErrorBlock:

FOR EACH Customer ON ERROR UNDO, THROW: FIND FIRST Order WHERE Order-Num = 1001. END. END PROCEDURE.

Page 18: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation18

Caller Enclosing Block

Returning Errors

Associated Block

ERETURN ERROR

Page 19: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation19

Returning Errors

RETURN ERROR [error string]

Return a Progress.Lang.AppError with error string

RETURN ERROR <error object>

Returns error of type error-object with

Page 20: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation20

/* MAIN.P */ RUN ErrorBlock IN hPersProc.

CATCH e AS Progress.Lang.AppError: MESSAGE e:GetMessage(1) VIEW-AS ALERT-BOX. DELETE e. END CATCH.

PROCEDURE ErrorBlock:

FOR EACH Customer ON ERROR UNDO, LEAVE: FIND FIRST Order WHERE Order-Num = 1001 NO-ERROR. IF ERROR-STATUS:ERROR THEN

RETURN ERROR NEW OrdNotFoundError(“1001”). END.

END PROCEDURE.

Let’s look at the code

Page 21: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation21

A Few Words About NO-ERROR

NO-ERROR Continues to suppress errors at the statement level

NO-ERROR Can handle errors raised via UNDO, THROW

NO-ERROR Converts information from error objects to ERROR-STATUS

Page 22: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation22

What that means is…

NO-ERROR

DO ON ERROR

CATCH RETURN ERROR

UNDO, THROW

ERROR condition

Generate any error

Handle any error

Page 23: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation23

Enclosing Block

Finally

Catch

Associated Block

And FINALLY…

Always executes on success or

failure

Page 24: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation24

Let’s look at the code

PROCEDURE ErrorBlock:

FOR EACH Customer: FIND FIRST Order WHERE Order-Num = 1001.

CATCH e AS Progress.Lang.SysError: MESSAGE e:GetMessage(1) VIEW-AS ALERT-BOX. DELETE OBJECT e. END CATCH.

FINALLY: /* clean up code */ END FINALLY. END.

END PROCEDURE.

Page 25: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation25

hSrv:CONNECT(…)NO-ERROR.

IF ERROR-STATUS:NUM-MESSAGES > 0 THEN:

MESSAGE “Connect Failed!” VIEW-AS ALERT-BOX.

Change in Behavior

With traditional error handling…

hSrv:CONNECT(…).

CATCH err AS Progress.Lang.SysError:

END CATCH.

With structured error handling…

Does Not Raise Error

Raises Error

Page 26: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation26

What About User-defined Functions?

Q: Will RETURN ERROR in a udf raise error in the caller?

A: No.

Q: Is there another way to raise error from a udf?

A: YES!

Page 27: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation27

FUNCTION foo RETURNS INTEGER ():

RETURN ERROR.

END FUNCTION.

Raising Error from User-defined Functions

With RETURN ERROR…

FUNCTION foo RETURNS INTEGER ():

UNDO, THROW NEW AcmeError().

END FUNCTION.

With structured error handling…

Does Not Raise Error

in Caller

Raises Error in Caller

Page 28: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation28

In Summary

Uniform model for handling error conditions

More flexibility for application specific errors

Traditional and structured error handling models co-exist

Page 29: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation29

Related Presentations

DEV-12 What’s New in the Object-Oriented ABL

DEV-22 Catch Me If You Can – Practical Structured Error Handling

DEV-32 Using the Advanced GUI, Structured Error Handling and SonicMQ to Build Semi-Disconnected Point of Sales

Page 30: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation30

Questions?

Page 31: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation31

Thank You

Page 32: A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.

© 2008 Progress Software Corporation32