[Grace-core] Exceptions design

James Noble kjx at ecs.vuw.ac.nz
Mon Aug 27 00:57:44 PDT 2012


On 26/08/2012, at 11:14 AM, Michael Homer wrote:

> Hi,
> From discussions in the last videoconference and afterwards, a basic
> idea of how Grace exceptions might work emerged. This is my vision of
> it, but others may have seen it differently.

not wanting to repeat all Michael's email - this looks fine to me.

one question I have is whether this is enough to support "Automatic Resource Management"
i.e. the "using" statement etc.  See e.g. the Java 7 version here:

http://www.oracle.com/technetwork/articles/java/trywithresources-401775.html

or the Baroque Scala version here:  https://github.com/jsuereth/scala-arm

> I'm looking for comments or clarifications of all that before I
> implement something like it.

So one clarification I guess we should put out into the open is why we didn't
adopt a more "OO" Java/C# design - with each exception type being a class,
and the exception hierarchy being the class hierarchy. (If it's not obvious that
Michael's design is quite different to that, please reread his email!)

The reason is that exceptions seem to be a great fit for *nominal* classes and types - 
which is just what Java has. We could use a Grace class to define a particular exception, 
but we couldn't match exceptions on that class (or use it as a type) because Grace
classes aren't types. Then we could define a *type* but that only gives the interface:
without proper brands (or pseudobrands, e.g. a method with the name of the exception)
there's probably little distinction between the types of different kind of exception instances.

This model finesses all these problems: exceptions are all instances of a single "class"
(or rather, all just similar objects) that pretty much have the same type, similarly 
exception "packets" are just objects created when the exceptions are thrown:
exceptions at as patterns that match the packets.   

On the whole, I'll choose to consider the ease by which other "class like" objects 
can be added to Grace is strength of the design, not a weakness..

James


More information about the Grace-core mailing list