Cliff Hacks Things.

Sunday, March 12, 2006

Runtime type information and exception handling

The design of Mongoose includes a number of 'little experiments.'

For example, Mongoose doesn't provide a standard way to determine an object's class. This is on purpose; the class of an object is an implementation detail. You can use the reflection API to find out if you really need to know, but chances are, you don't. Instead, you can check an object for conformance to a certain protocol (a set of messages), and the object may very well change its conformance at runtime.

I've managed to implement most of the Mongoose standard library in this fashion, but I've hit a bit of a roadblock: structured exception handling.

Specifically, it's really nice to be able to define a number of exception handlers, specialized on the type of exception encountered. The traditional way to do this in languages like Java is to specialize on the exception's class.

Sure, I could do this other ways — say, check some 'exception type' parameter — but it feels like a workaround, and requires another layer of namespace to avoid collisions.

This will require some thought.


Post a Comment

<< Home