1 / 32

A5: Structured Error Handling in the ABL

A5: Structured Error Handling in the ABL. Phillip Malone. Senior Technical Support Engineer. Structured Error Handling -- Agenda. Overview of the old and new Catching errors Raising errors The FINALLY block Changes to be aware of. Traditional Error Handling Model.

salali
Download Presentation

A5: Structured Error Handling in the ABL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Structured Error Handling -- Agenda • Overview of the old and new • Catching errors • Raising errors • The FINALLY block • Changes to be aware of

  3. Traditional 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]

  4. Traditional 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

  5. A Bit About Blocks

  6. A Bit About Blocks Outer Block ON ERROR RETRY NEXT LEAVE RETURN UNDO, Inner Block

  7. A Bit About Blocks Outer Block ON ERROR RETRY NEXT LEAVE RETURN UNDO, Inner Block E

  8. Structured 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 <error object>

  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. Catching Errors Enclosing Block ON ERROR UNDO, RETRY NEXT LEAVE RETURN Associated Block Catch E

  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. Object Hierarchy Progress.Lang.Object Progress.Lang. Error <<interface>> Progress.Lang.ProError Progress.Lang.SysError Progress.Lang.AppError Progress.Lang. SoapFaultError User-Defined Error Objects

  13. Error Objects Properties available on ProError NumMessages, Severity, CallStack Methods available on ProError GetMessage(), GetMessageNum() Additional Methods and Properties on AppError AddMessage(), RemoveMessage() ReturnValue

  14. Throwing Errors Enclosing Block ON ERROR UNDO, RETRY LEAVE NEXT RETURN Associated Block E THROW

  15. Throwing Errors Overrides default ON ERROR of routine level blocks ROUTINE-LEVEL ON ERROR UNDO, THROW Explicitly throws (or re-throws) an error UNDO, THROW <error object>

  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. 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. Returning Errors Enclosing Block Caller Associated Block RETURN ERROR E

  19. Returning Errors Return a Progress.Lang.AppError with error string RETURN ERROR [error string] Returns error of type error-object with RETURN ERROR <error object>

  20. Let’s look at the code /* 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.

  21. A 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

  22. What that means is… Handle any error NO-ERROR DO ON ERROR CATCH Generate any error RETURN ERROR UNDO, THROW ERROR condition

  23. And FINALLY… Enclosing Block Always executes on success or failure Associated Block Catch Finally

  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. Change in Behavior Does Not Raise Error With traditional error handling… hSrv:CONNECT(…)NO-ERROR. IF ERROR-STATUS:NUM-MESSAGES > 0 THEN: MESSAGE “Connect Failed!” VIEW-AS ALERT-BOX. Raises Error With structured error handling… hSrv:CONNECT(…). CATCH err AS Progress.Lang.SysError: … END CATCH.

  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. Raising Error from User-defined Functions Does Not Raise Error in Caller With RETURN ERROR… 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.

  28. In Summary • Uniform model for handling error conditions • More flexibility for application specific errors • Traditional and structured error handling models co-exist

  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. ? Questions

  31. Thank You

More Related