Most modern Smalltalk80 implementations have more or less converged on a standard exceptions framework as set out in the ANSI spec.

There’s a description here (it’s for Pharo, but is more or less the same as for Squeak, GnuSmalltalk etc)

Self doesn’t have an exceptions framework. There is a generally available ‘error:’ message, whose meaning is globally defined; apart from that there is a preference for passing error handlers to methods which are likely to need them (such as ‘at:IfAbsent:’ or ‘do:IfFail:’).

Is this enough?

An ANSI Smalltalk style framework should be doable. The core mechanism is winding up the stack and searching it for a suitable handler, which shouldn’t require any adjustment of the VM. The question is whether we want to.

The plus side is that ports of open source Smalltalk80 code might be made easier. For example, both SUnit and the new Xtreams stream library have built exception handling into the way they do things.

However, even if we adopt the idea of resumable exceptions, our framework would be likely to be different. The ANSI system is class based and relies on hierarchies of exceptions, where an EndOfStream signal is a subclass of an Exception which is a subclass of Error (or vice versa)

For Pharo this looks like:

Blimey!

This of course leads to the well known code pattern of:

| result |
result := [(StandardFileStream oldFileNamed: 'error42.log') contentsOfEntireFile]
    on: FileDoesNotExistException
    do: [:ex | ex fileName , ' not available'].
Transcript show: result; cr

This feels rather unSelflike (unselfish? unselbstlich?). It relies on the identity of objects to determine what happens to them, and also their class membership – confusing the object’s name (ie the path to the object from the lobby) with the object’s identity and behaviour and using a deep class hierarchy as an adhoc pattern matching mechanism.

Part of what I would like Self to do is to move away from unecessary reliance on the lobby as a guarantor of identity, and adopting a rigid lobby based mechanism for determining exception behaviour  wouldn’t help.

If the standard class based ANSI exceptions framework is not suitable for Self, what are the options? Is a stack searching resumable exception framework something which should be aimed for at all? Or should the concept of passing exception handlers to objects be explored further?

Advertisements