Navigation: Programming Cookbook > Exception Handling >
Class vs Instance
There are two broad categories of exception handling systems in Smalltalk implementations:
|1.||Class based, as exemplified by Dolphin.|
|2.||Instances (or Signal) based, as exemplified by the legacy exception system in VisualWorks™|
Although the instance-based mechanism does have a slight space advantage (no new classes are needed), this is outweighed by the advantages of a class-based mechanism, such as the ability to add state and behaviour. In fact the exception handling specified in the ANSI standard for Smalltalk is class-based.
Dolphin has a class based exception mechanism that is compliant with the ANSI standard, but also implements an instance-based mechanism on top of this (Signal).
In Dolphin's class based exception handling implementation, exceptions are represented by subinstances of the class Exception. Specific types of exception are instantiated and signalled (e.g. by sending the #signal: message to the class), after which user defined exception handlers can catch (typically by specifying the relevant class or classes of exception) and handle them. Exception handlers are normal Smalltalk blocks, but can also affect the execution state (e.g. to unwind the stack up to that point, or to continue execution as if nothing had happened) by sending messages to the exception itself, which is passed to the handler block as an argument.
The user is free to define new classes of exception, so an exception can include whatever information about the error condition that is required, and one can also define methods to add (or override) behaviour..