Title: DEV-8: Structured Error Handling in the ABL
1DEV-8 Structured Error Handling in the ABL
Sarah Marshall
QA Architect
2Structured Error Handling -- Agenda
- Overview of the old and new
- Catching errors
- Raising errors
- The FINALLY block
- Changes to be aware of
3Traditional Error Handling Model
- Behavior handled at the statement level
NO-ERROR / ERROR-STATUS
Behavior handled locally at the block level
ON ERROR, UNDO LEAVE RETRY
Application can return error to its caller
RETURN ERROR error string
4Traditional Error Handling Model
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
5A Bit About Blocks
6A Bit About Blocks
Outer Block
ON ERROR RETRY NEXT LEAVE RETURN
UNDO,
Inner Block
7A Bit About Blocks
Outer Block
ON ERROR RETRY NEXT LEAVE RETURN
UNDO,
Inner Block
E
8Structured Error Handling Model 10.1C
- CATCH blocks to handle all error types
CATCH err AS Progress.Lang.Error
Ability to create user-defined application errors
myError INHERITS Progress.Lang.AppError
Facilities to propagate errors up the call stack
UNDO, THROW lterror objectgt
9Lets look at the code
PROCEDURE ErrorBlock FOR EACH Customer ON
ERROR UNDO, LEAVE FIND FIRST Order WHERE
Order-Num 1001 NO-ERROR. IF
ERROR-STATUSERROR THEN MESSAGE
ERROR-STATUSGET-MESSAGE(1). FIND FIRST
Order WHERE Order-Num 1002. END. END
PROCEDURE.
10Catching Errors
Enclosing Block
ON ERROR UNDO, RETRY NEXT LEAVE RETURN
Associated Block
Catch
E
11Lets look at the code
PROCEDURE ErrorBlock FOR EACH Customer
FIND FIRST Order WHERE Order-Num 1001.
CATCH e AS Progress.Lang.SysError MESSAGE
eGetMessage(1) VIEW-AS ALERT-BOX. DELETE
OBJECT e. END CATCH. END. END PROCEDURE.
12Object Hierarchy
Progress.Lang.Object
Progress.Lang. Error ltltinterfacegtgt
Progress.Lang.ProError
Progress.Lang.SysError
Progress.Lang.AppError
Progress.Lang. SoapFaultError
User-Defined Error Objects
13Error Objects
Properties available on ProError
NumMessages, Severity, CallStack
Methods available on ProError
GetMessage(), GetMessageNum()
Additional Methods and Properties on AppError
AddMessage(), RemoveMessage() ReturnValue
14Throwing Errors
Enclosing Block
ON ERROR UNDO, RETRY LEAVE NEXT RETURN
Associated Block
E
THROW
15Throwing Errors
Overrides default ON ERROR of routine level blocks
ROUTINE-LEVEL ON ERROR UNDO, THROW
Explicitly throws (or re-throws) an error
UNDO, THROW lterror objectgt
16Lets look at the code
PROCEDURE ErrorBlock FOR EACH Customer ON
ERROR UNDO, LEAVE FIND FIRST Order WHERE
Order-Num 1001 NO-ERROR. IF
ERROR-STATUSERROR THEN MESSAGE
ERROR-STATUSGET-MESSAGE(1). END. END
PROCEDURE.
17Lets 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.
18Returning Errors
Enclosing Block
Caller
Associated Block
RETURN ERROR
E
19Returning Errors
Return a Progress.Lang.AppError with error string
RETURN ERROR error string
Returns error of type error-object with
RETURN ERROR lterror objectgt
20Lets look at the code
/ MAIN.P / RUN ErrorBlock IN hPersProc.
CATCH e AS Progress.Lang.AppError MESSAGE
eGetMessage(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-STATUSERROR THEN RETURN ERROR NEW
OrdNotFoundError(1001). END. END PROCEDURE.
21A Few Words About 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
NO-ERROR
22What that means is
Handle any error
NO-ERROR DO ON ERROR CATCH
Generate any error
RETURN ERROR UNDO, THROW ERROR condition
23And FINALLY
Enclosing Block
Always executes on success or failure
Associated Block
Catch
Finally
24Lets look at the code
PROCEDURE ErrorBlock FOR EACH Customer
FIND FIRST Order WHERE Order-Num 1001.
CATCH e AS Progress.Lang.SysError MESSAGE
eGetMessage(1) VIEW-AS ALERT-BOX. DELETE
OBJECT e. END CATCH. FINALLY /
clean up code / END FINALLY. END. END
PROCEDURE.
25Change in Behavior
- With traditional error handling
Does Not Raise Error
hSrvCONNECT()NO-ERROR. IF ERROR-STATUSNUM-MESSA
GES gt 0 THEN MESSAGE Connect Failed! VIEW-AS
ALERT-BOX.
Raises Error
With structured error handling
hSrvCONNECT(). CATCH err AS Progress.Lang.SysErr
or END CATCH.
26What 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!
27Raising Error from User-defined Functions
Does Not Raise Error in Caller
FUNCTION foo RETURNS INTEGER () RETURN
ERROR. END FUNCTION.
Raises Error in Caller
With structured error handling
FUNCTION foo RETURNS INTEGER () UNDO, THROW
NEW AcmeError(). END FUNCTION.
28In Summary
- Uniform model for handling error conditions
- More flexibility for application specific errors
- Traditional and structured error handling models
co-exist
29Related Presentations
- DEV-12 Whats 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
30?
Questions
31Thank You
32(No Transcript)