Sunday, 17 January 2010

Failsafe application development: a visual as to how (exceptions)


Probably the last in this series for this weekend, this post is showing how exceptions can be perfectly handled. It builds on to my last post visualising error handling

For starters, every function, module or program should always have a safety net. I'm going to use the well-know catch-try mechanisms as an example

What was the goal again? To not suffer from memory-loss, i.e. whenever you're hit by an exception you stand ground, collect all evidence, and gracefully exit

Here's how, visualised. For the concept, read my first post on this

TRY
IF NOT CARD VALID THEN
-->ERROR: CARD INVALID
EXIT

IF NOT AUTHORISATION OKAY THEN
-->ERROR: AUTHORISATION NOT OKAY
EXIT

IF NOT ENOUGH CREDIT THEN
-->ERROR: NOT ENOUGH CREDIT
EXIT

CATCH

THE-OBJECT.CARD = CARD
THE-OBJECT.AUTHORISATION = AUTHORISATION
THE-OBJECT.CREDIT = CREDIT

THE-OBJECT.CUSTOMER-OBJECT = CUSTOMER-OBJECT

The last is adding this function's Customer object to The Object, courtesy of Lee Provoost so to say.
As you can see, this is an easy way to store all local variables and their run-time values. In some programming languages you're even able to acces these as properties of the function itself

Run-time values needed in other functions can also be assigned to The Object this way -albeit not at the place where you catch exceptions of course-, leaving the function's return value to tell you whether it was successful or not

Yes this might create a great big huge object with all run-time values, but then again that's exactly what you want, isn't it?

0 reacties:

Post a comment

Thank you for sharing your thoughts! Copy your comment before signing in...