A5: Structured Error Handling in the ABL Phillip Malone Senior Technical Support Engineer.
-
Upload
edwina-elliott -
Category
Documents
-
view
216 -
download
0
Transcript of 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
© 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
© 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
© 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
© 2008 Progress Software Corporation5
A Bit About Blocks
© 2008 Progress Software Corporation6
UNDO,ON ERROR
RETRYNEXTLEAVERETURN
A Bit About Blocks
Outer Block
Inner Block
© 2008 Progress Software Corporation7
UNDO,ON ERROR
RETRYNEXTLEAVERETURN
A Bit About Blocks
Outer Block
Inner Block
E
© 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>
© 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.
© 2008 Progress Software Corporation10
ON ERROR UNDO,
RETRYNEXT LEAVERETURN
Catching Errors
Enclosing Block
Associated Block
Catch E
© 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.
© 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>>
© 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
© 2008 Progress Software Corporation14
ON ERROR UNDO,
RETRYLEAVENEXTRETURN
Throwing Errors
Enclosing Block
Associated Block
E
THROW
© 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
© 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.
© 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.
© 2008 Progress Software Corporation18
Caller Enclosing Block
Returning Errors
Associated Block
ERETURN ERROR
© 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
© 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
© 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
© 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
© 2008 Progress Software Corporation23
Enclosing Block
Finally
Catch
Associated Block
And FINALLY…
Always executes on success or
failure
© 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.
© 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
© 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!
© 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
© 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
© 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
© 2008 Progress Software Corporation30
Questions?
© 2008 Progress Software Corporation31
Thank You
© 2008 Progress Software Corporation32