Download presentation
Presentation is loading. Please wait.
Published byEdwina Elliott Modified over 9 years ago
1
A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer
2
© 2008 Progress Software Corporation 2 Structured Error Handling -- Agenda Overview of the old and new Catching errors Raising errors The FINALLY block Changes to be aware of
3
© 2008 Progress Software Corporation 3 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
4
© 2008 Progress Software Corporation 4 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
5
© 2008 Progress Software Corporation 5 A Bit About Blocks
6
© 2008 Progress Software Corporation 6 UNDO, ON ERROR RETRY NEXT LEAVE RETURN A Bit About Blocks Outer Block Inner Block
7
© 2008 Progress Software Corporation 7 UNDO, ON ERROR RETRY NEXT LEAVE RETURN A Bit About Blocks Outer Block Inner Block E
8
© 2008 Progress Software Corporation 8 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
9
© 2008 Progress Software Corporation 9 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.
10
© 2008 Progress Software Corporation 10 ON ERROR UNDO, RETRY NEXT LEAVE RETURN Catching Errors Enclosing Block Associated Block Catch E
11
© 2008 Progress Software Corporation 11 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.
12
© 2008 Progress Software Corporation 12 Object Hierarchy Progress.Lang.Object Progress.Lang.ProError Progress.Lang.AppError Progress.Lang.SysError Progress.Lang. SoapFaultError User-Defined Error Objects Progress.Lang. Error >
13
© 2008 Progress Software Corporation 13 Error Objects NumMessages, Severity, CallStack Properties available on ProError GetMessage(), GetMessageNum() Methods available on ProError AddMessage(), RemoveMessage() ReturnValue Additional Methods and Properties on AppError
14
© 2008 Progress Software Corporation 14 ON ERROR UNDO, RETRY LEAVE NEXT RETURN Throwing Errors Enclosing Block Associated Block E THROW
15
© 2008 Progress Software Corporation 15 Throwing Errors ROUTINE-LEVEL ON ERROR UNDO, THROW Overrides default ON ERROR of routine level blocks UNDO, THROW Explicitly throws (or re-throws) an error
16
© 2008 Progress Software Corporation 16 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.
17
© 2008 Progress Software Corporation 17 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.
18
© 2008 Progress Software Corporation 18 Caller Enclosing Block Returning Errors Associated Block E RETURN ERROR
19
© 2008 Progress Software Corporation 19 Returning Errors RETURN ERROR [error string] Return a Progress.Lang.AppError with error string RETURN ERROR Returns error of type error-object with
20
© 2008 Progress Software Corporation 20 /* 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
21
© 2008 Progress Software Corporation 21 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
22
© 2008 Progress Software Corporation 22 What that means is… NO-ERROR DO ON ERROR CATCH RETURN ERROR UNDO, THROW ERROR condition Generate any error Handle any error
23
© 2008 Progress Software Corporation 23 Enclosing Block Finally Catch Associated Block And FINALLY… Always executes on success or failure
24
© 2008 Progress Software Corporation 24 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.
25
© 2008 Progress Software Corporation 25 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
26
© 2008 Progress Software Corporation 26 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!
27
© 2008 Progress Software Corporation 27 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
28
© 2008 Progress Software Corporation 28 In Summary Uniform model for handling error conditions More flexibility for application specific errors Traditional and structured error handling models co-exist
29
© 2008 Progress Software Corporation 29 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
30
© 2008 Progress Software Corporation 30 Questions ?
31
© 2008 Progress Software Corporation 31 Thank You
32
© 2008 Progress Software Corporation 32
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.