Navigation:  Programming Cookbook >

Exception Handling

Previous pageReturn to chapter overviewNext page

Early versions of Smalltalk did not have exceptions, and provided no particular support for error handling. Exception handling schemes that by-pass the normal flow of control, and which use objects to represent error conditions, have a number of advantages over other error handling techniques, such as testing return values:

Error handling code can be separated from normal code. In particular the frequent and repetitive testing of return values, and propagation of error return values, is not required. Since exceptional conditions can normally be ignored, code can be less complex, less likely to contain bugs, and easier to read.
Error return values can be ignored, exceptions cannot. In practice lazy or pressurised programmers frequently do not test for failure codes.
The range of return values may not include any space for error values, hence the rather confusing technique (used in OLE) of returning values through "out" parameters and using the return value for success and error codes only. Exceptions by-pass the stack, so there is no possibility of conflict.
The point at which an error occurs is rarely a suitable place to handle it, particularly in library code, but by the time the error has been propagated to a place where it can be handled, too much contextual information has been lost. Exceptions bridge this gap - they allow specific error information to be carried from the point where it available to a point where it can be utilised.
Resumable exception models can be used to construct resilient systems that carry out repairs when exceptions occur, with subsequent resumption of execution as if nothing had happened. For example, this technique is useful for on-demand resource allocation.
Using exceptions may be more efficient because the normal execution path does not need to test for error conditions.

The end result of all these advantages is, hopefully, faster development of more robust and easier to maintain systems. Consequently exception-handling schemes have found there way into more recent versions of Smalltalk, and Dolphin is no exception.