New Release of Essence#: The ‘Ark’ release introduces Exception handling.

The ‘Ark’ release adds support for raising and handling Exceptions–for those times when the seas get rough and you need a boat to get you safely through “exceptional” conditions 🙂 The release also includes fixes for a few bugs that were discovered as a side effect of introducing Exceptions.

Complete documentation of the new features and capabilities will be forthcoming over the next few days, but here’s a brief summary, with examples:

#ensure: aBlock

To ensure that critical code runs no matter what, put your business logic in a zero-argument block, and run it by sending the message #ensure: with a zero-argument block as the message argument. The second block will be run when the first block finishes, or if the first block is aborted by an exception:

[self processFiles] ensure: [self closeFiles]

#ifCurtailed: aBlock

To make sure that a block of code runs if and only if the main logic path is aborted by an exception (“curtailed,”) put the main logic path in a zero-argument block and evaluate it by sending the message #ifCurtailed:, with a zero-argument block as the message argument. The second block will be run if and only if the first block is aborted by an exception:

[self doBusinessLogic] ifCurtailed: [self handleFailure]

#on: ExceptionClass do: oneArgBlock

To protect your business logic with an exception handler, put it in a zero-argument block and send the block the message #on:do: with an Exception class as the first message argument and a one-argument block as the second message argument. If an exception is raised during the processing of the block that is sent the #on:do: message, and if sending the message #handles: theException to the ExceptionClass evaluates to true, then the oneArgBlockwill be evaluated with the raised exception as its argument:

[self doNormalApplicationActivity] 
            on: MessageNotUnderstood
            do: [:exception | 
                    exception 
                            addTo: EventLog;
                            notifyUser.
                    self ensureGracefulShutdown]

 

#signal and #signal: messageText

To signal (raise, throw) an exception, send either the message #signal (with no argument) or #signal: aString to the class of the exception you would like to raise:

Warning signal: ‘Tsunami detected offshore!’

And that’s the end of the executive summary. Much more documentation will be published about Exceptions over the next few days.

The new release is available from the Essence# site on CodePlex.

Advertisements

3 responses to “New Release of Essence#: The ‘Ark’ release introduces Exception handling.

  1. Thanks for explaining where to find them. Due to some installer glitch (that I cannot reproduce) I did not get those files first time around. I ran the installer again today, and got a full source distribution, including the *.csproj files, in a “Visual Studio 2013” folder.

    As an aside, you might find it easier to run git init in the top folder that contains EssenceSharp.csproj, thus capturing any changes you make to the user guide and project file and synchronizing with the source code, without any special effort on your part to make a separate download. (Your audience could keep up to date by running git pull.)

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s