ABL Structured Error Handling -...

79
ABL Structured Error Handling Mike Fechner Director

Transcript of ABL Structured Error Handling -...

Page 1: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

ABL Structured Error Handling

Mike FechnerDirector

Page 2: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved. 3

Page 3: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Consultingwerk Software Services Ltd.

4

Independent IT consulting organization Focusing on OpenEdge and related technology Located in Cologne, Germany, subsidiaries in UK and Romania Customers in Europe, North America, Australia and South Africa Vendor of developer tools and consulting services Specialized in GUI for .NET, Angular, OO, Software Architecture,

Application Integration Experts in OpenEdge Application Modernization

Page 4: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Mike Fechner Director, Lead Modernization Architect and

Product Manager of the SmartComponent Library and WinKit

Specialized on object oriented design, software architecture, desktop user interfacesand web technologies

28 years of Progress experience (V5 … OE11)

Active member of the OpenEdge community Frequent speaker at OpenEdge related

conferences around the world5

Page 5: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

SmartComponent Library framework Helps to protect your investment in your OpenEdge based

application The framework is designed to modernize existing OpenEdge

applications and to provide the foundation of new projects In the cloud and on premise UI flexibility – Desktop, Web & Mobile The architecture of the SmartComponent Library simplifies

integration with future technologies and the implementation of new business requirements.

6

Page 6: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved. 7

Page 7: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Agenda Traditional/Classic Error Handling recap Structured Error Handling Combining Structured and Classic Err. Handling STOP Conditions Error Handling best practices

ABL Structured Error Handling

8

Page 8: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Runtime „conditions“ (Runtime) Error

Application Error

Stop Conditions

Quit Conditions

ABL Structured Error Handling

9

Page 9: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Classic Error Handling Block oriented error handling Error handling directives (ON ERROR …) Intuitively used by experienced ABL developers Made more sense in TTY data entry

NO-ERROR option on a number of statement ERROR-STATUS System Handle RETURN ERROR <return value> NO-UNDO for variables and temp-tables

ABL Structured Error Handling

10

Page 10: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Error handling sequence in a block

Stops execution of current block

Display error message

Undo transaction or sub-transaction (if present)

Branch action (RETRY, LEAVE, NEXT)

ABL Structured Error Handling

11

Page 11: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Default branching options per block type

ABL Structured Error Handling

12

(CATCH/FINALLY)

Page 12: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Routine-level blocks .p file, .w file Internal procedure User-defined function Database trigger User-interface trigger Class method, including Constructor GET/SET Destructor

ABL Structured Error Handling

13

Page 13: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

14

Page 14: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

15

Page 15: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

16

Page 16: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

17

Page 17: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Classic Error Handling Issues Default Branching not always optimal for non TTY UI processing

ABL Structured Error Handling

18

Page 18: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Classic Error Handling Issues Calling statements with NO-ERROR leaves ERROR-STATUS behind ERROR-STATUS:ERROR and RETURN-VALUE need to be reset by ERROR-STATUS:ERROR = FALSE NO-ERROR RETURN "" .

Otherwise confusing if (pending) error was already handled or not

ABL Structured Error Handling

19

Page 19: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Agenda Traditional/Classic Error Handling recap Structured Error Handling Combining Structured and Classic Err. Handling STOP Conditions Error Handling best practices

ABL Structured Error Handling

20

Page 20: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Structured Error Handling Alternative way of handling errors in the ABL Adds error handling constructs known form OO languages such as C#

and Java to the ABL Based on OO-ABL elements Usable and useful with procedural code without exception (such as

classic error handling can be used in OO) Available since 10.1C, enhanced in 10.2A (garbage collection), 11.3

(block-level default), 11.4 (serializable error classes), 11.7 (stop-conditions)

ABL Structured Error Handling

21

Page 21: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

FINALLY Clean up code block, can be attached to the end of every undoable

block Executed when block succeeds, errors, executed per iteration of block

(loops) Can be nested Available since 10.1C

Must use! For everyone using dynamic queries etc… every code that requires clean up at runtime

ABL Structured Error Handling

22

Page 22: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

23

It should become your routine to add FINALLY Block close enough to CREATE object

statement

Page 23: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

CATCH Block to handle runtime errors in the surrounding block When error occurs: Block execution (iteration) stops Transaction or sub-transaction undone CATCH block execution

CATCH Block allows to inspect the error Any undoable block is a TRY block (no explicit TRY block needed in

the ABL)

ABL Structured Error Handling

24

Page 24: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

25

Page 25: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

CATCH CATCH block filters errors by type Multiple CATCH blocks can handle specific errors Should order CATCH blocks by specific to generic types First CATCH block matching the error that occurs handles it, following

CATCH blocks will not handle the error

ABL Structured Error Handling

26

Page 26: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

27

Page 27: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Error classes

ABL Structured Error Handling

28

class Progress.Lang

«interface»Error ProError

SysError AppError SoapFaultError

Object

«.NET»System.Exception

inheritsinherits inherits

implements

inherits

implements

Page 28: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

29

Page 29: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

30

Page 30: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Custom Error Class

ABL Structured Error Handling

31

Page 31: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

CATCH Custom Error

ABL Structured Error Handling

32

Page 32: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Demo Locate Consultingwerk.Exceptions.Exception in

http://help.consultingwerkcloud.com/smartcomponent_library/release/

ABL Structured Error Handling

33

Page 33: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Raising errors … THROW DEFINE VARIABLE err AS <myerror> .

err = NEW <myerror> (parameter) .err:CustomProperty = 42 . UNDO, THROW err .

UNDO, THROW NEW <myerror> (parameter) .

RETURN ERROR NEW <myerror> (parameter) .

ABL Structured Error Handling

34

Page 34: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

AppError constructors NEW AppError () NEW AppError (CHARACTER) NEW AppError (CHARACTER, INTEGER)

Attention: AppError (CHARACTER) and AppError (CHARACTER, INTEGER) behave differently

Signature suggest the INTEGER is for an optional parameter

ABL Structured Error Handling

35

Page 35: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

AppError constructors UNDO, THROW NEW AppError

(„this text is NOT shown“) . UNDO, THROW NEW AppError

(„this text is shown to the user“, 42) .

First statement initializes an AppError with a ReturnValue assigned (RETURN ERROR)

Second statement initializes an AppError with a message and severity/number assigned!

AVM only displays errors with message

ABL Structured Error Handling

36

Page 36: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

37

Page 37: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

THROW Branch option on blocks … <block statement> ON ERROR UNDO, THROW: FOR EACH Customer ON ERROR UNDO, THROW

When errors occur in the block, pass error for handling to next outer block Next outer block may also throw

Iterating block will NOT iterate any further First error terminates everything No more infinitive loops caused by errors!

ABL Structured Error Handling

38

Page 38: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

39

Page 39: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Problem: UNDO, THROW from routine

ABL Structured Error Handling

40

Page 40: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Problem: UNDO, THROW from routine

ABL Structured Error Handling

41

UNDO, THROW

Page 41: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ROUTINE-LEVEL ON ERROR UNDO, THROW

Declarative statement, available since 10.1C Must be placed before any executable statements, including DEFINE‘s May be after USING

Changes ERROR Branching option for ALL routine blocks in compile unit to ON ERROR UNDO, THROW

No effect on loops, DO TRANSACTION, DO ON ERROR

ABL Structured Error Handling

42

Page 42: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

43

Page 43: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

BLOCK-LEVEL ON ERROR UNDO, THROW

Declarative statement, available since 11.3 Must be placed before any executable statements, including DEFINE‘s May be after USING

Changes default ERROR Branching option for ALL blocks in compile unit to ON ERROR UNDO, THROW

May be redefined on loops, DO TRANSACTION, DO ON ERROR

Make this your default for new code, when on 11.3 +

ABL Structured Error Handling

44

Page 44: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

45

Page 45: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

BLOCK-LEVEL ON ERROR UNDO, THROW

Don’t get used to BLOCK-LEVEL ON ERROR when still deploying to 10.1C – 11.2

Don’t switch between ROUTINE-LEVEL and BLOCK-LEVEL using PROVERSION preprocessor

Error handling should be tested during development And behave 100% the same way at runtime Surprises in error handling are expensive …

ABL Structured Error Handling

46

Page 46: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Re-THROW

ABL Structured Error Handling

47

Page 47: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Re-THROW of Progress.Lang.SysError Runtime error often the root cause for application raised error Application raised error may be adding context

Unexpected SysError should be re-thrown

Developers need to “track” possible runtime error numbers themselves – as no (complete) list of errors expected per ABL statement or Widget method is available

Attention: Error message numbers may change with new Openedgereleases (like DYNAMIC-INVOKE in 11.6)

ABL Structured Error Handling

48

Page 48: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Agenda Traditional/Classic Error Handling recap Structured Error Handling Combining Structured and Classic Err. Handling STOP Conditions Error Handling best practices

ABL Structured Error Handling

49

Page 49: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Combining Structured and Classic Error Handling

THROW and classic error handling fully compatible AppError or any of the runtime error handled based on branch action of

receiving block: RETRY NEXT LEAVE RETURN

ABL Structured Error Handling

50

Page 50: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

51

ON ERROR UNDO, RETRYBecause of FRAME based UI

Page 51: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

52

ON ERROR UNDO, RETRYBecause of FRAME based UI

Page 52: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Combining Structured and Classic Error Handling

All errors available through ERROR-STATUS system handle AppError with ReturnValue same impact as RETURN ERROR <return-

value>

ABL Structured Error Handling

53

Page 53: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Recommendation Do not add ROUTINE-LEVEL or BLOCK-LEVEL Error Handling to

existing code without testing! Users may be used to executing reports with a few „Item record not on

file“ messages Adding ROUTINE-LEVEL or BLOCK-LEVEL error handling will

severely impact the program flow! Users may not be able to receive the report they need to get their job

done – and may have only little understanding for a developer now happy with better error handling

ABL Structured Error Handling

54

Page 54: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Agenda Traditional/Classic Error Handling recap Structured Error Handling Combining Structured and Classic Err. Handling STOP Conditions Error Handling best practices

ABL Structured Error Handling

55

Page 55: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

STOP Conditions Critical system error RUN non-existing .p file .r code CRC does not match schema trigger r. code not matching the CRC stored in DB schema DB connection missing/lost … STOP-AFTER (unfortunately) -lkwtmo (lock wait time-out)

ABL Structured Error Handling

56

Page 56: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

STOP Condition handling UNDO blocks until it reaches an ON STOP Block AVM may decide to skip ON STOP and proceed with reverting … Eventually may restart client startup procedure

FINALLY Blocks are NOT executed! (change in OpenEdge 11.7!!!)

ABL Structured Error Handling

57

Page 57: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Convert STOP into AppError STOP can be handled by RETURN ERROR FINALLY will be executed

ABL Structured Error Handling

58

Page 58: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Handling of STOP Conditions (OpenEdge 11.7) Technology preview of handling STOP conditions based on structured

error handling added in OpenEdge 11.7 Public beta test for that feature -catchStop 1 Startup Parameter, requires recompilation, must be set

for compile and runtime session

It is expected that in OpenEdge 12 –catchStop 1 becomes the new default

ABL Structured Error Handling

59

Page 59: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

STOP Condition Handling classes No Progress.Lang.Error Progress.Lang.Stop - STOP Statement Progress.Lang.LockConflict - -lkwtmo exceeded Progress.Lang.StopAfter - STOP-AFTER exceeded Progress.Lang.UserInterrrupt - CTRL-BREAK

Progress.Lang.Error derived Progress.Lang.StopError - RUN invalid.p, etc.

ABL Structured Error Handling

60

Page 60: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

61

Page 61: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Agenda Traditional/Classic Error Handling recap Structured Error Handling Combining Structured and Classic Err. Handling STOP Conditions Error Handling best practices

ABL Structured Error Handling

62

Page 62: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Error Stack Trace For debugging purposes the stack trace (where an error occurred) can

be more relevant to know than the actual error message Traditional MESSAGE statement “Help” (-debugalert) shows stack

trace of the message When Structured Error Handling was introduced, Progress was afraid

that gathering the Error Stack trace would be expensive at runtime Progress recently corrected this statement: Runtime penalty of

collecting the error stack is very minimal

63

Page 63: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Error Stack Trace Property on the Progress.Lang.Error interface Requires -errorstack Startup Parameter Or SESSION:ERROR-STACK-TRACE = TRUE

64

Page 64: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved. 65

Page 65: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved. 66

Page 66: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Implement default error handler A standard CATCH block to be used in most places where errors

should be shown or written to the AppServer logfile Display error message(s) or RETURN-VALUE Display error-stack Display additional properties of error object

67

Page 67: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Errors should be exceptional Errors are called “Exception” in .NET and Java

Don‘t use errors as alternative RETURN-VALUE Errors should not happen on a regular basis Error handling is an relatively expensive operation Block-Transaction will be undone in every case

ABL Structured Error Handling

68

Page 68: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

CATCH in every Event handlers When using structured error handling, every UI event handler should

have a CATCH Classic ABL GUI TTY GUI for .NET

If you don’t show messages by then the AVM will do Only way to create nice and feature-rich error dialog

ABL Structured Error Handling

69

Page 69: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

70

Page 70: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

CATCH in worker methods Non UI code, batch routines, code that is calculating values etc. Worker methods on the other end, should not show error messages, all

errors should be thrown Worker methods should only CATCH error that can be handled with no

user interaction open query if not open, then re-run delete dynamic query widget, when QUERY-PREPARE-FAILED perform any kind of useful alternative action or clean-up on error

ABL Structured Error Handling

71

Page 71: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Avoid NO-ERROR Statements with NO-ERROR cannot be handled with a CATCH block

hQuery:QUERY-PREPARE (“…”) NO-ERROR

Only way to handle this is ERROR-STATUS:ERROR or explicit checks IF AVAILABLE Customer

ERROR-STATUS:ERROR valid until next statement is executed with NO-ERROR

ABL Structured Error Handling

72

Page 72: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

InnerException Pattern Known from .NET Useful to „upgrade“ certain runtime errors to application errors (similar

to RE-THROW) Keep original error information, such as Stack-Trace, ReturnValue,

error messages, custom properties When error happens, it happens, … all I can do in some locations is to

add context data, to simplify debugging See Consultingwerk.Exceptions.Exception and DataAccess class

ABL Structured Error Handling

73

Page 73: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

ABL Structured Error Handling

74

Page 74: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Code Review Consultingwerk.Exceptions.Exception InnerException Implementation SessionInfo from AppServer to Client

ABL Structured Error Handling

75

Page 75: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Assertions Concept for validating method parameters Verify a value Throw an error when expected condition is not met Static methods Simple way to provide consistent errors for common issues

ABL Structured Error Handling

76

Page 76: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Example from BufferAssert Consultingwerk.Assertion.BufferAssert:HasField (hBuffer, “CustNum”) .

ABL Structured Error Handling

77

Page 77: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Questions

78

Page 78: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.

Win an Amazon Echo Spot

79

Answer the question and be in with a chance to win an Amazon Echo Spot.The winner will be announced on Thursday during the Consultingwerk session at 14.45: An introduction into managing dependencies in OOABL applications – or OO patterns every ABL developer should know.

Simply complete the registration card to qualify.

WHAT ANNIVERSARY IS THE SMARTCOMPONENT LIBRARY CELEBRATING?

Page 79: ABL Structured Error Handling - pugsa.orgpugsa.org/wp-content/uploads/2019/03/MF_Strucutred-Error-Handling.pdf · Übersicht © 2019 Consultingwerk Software Services Ltd. All rights

Übersicht

© 2019 Consultingwerk Software Services Ltd. All rights reserved.