prev back next

Exceptions and Signals

Smalltalk provides a powerful and flexible mechanism to handle exceptions and errors in a graceful way. Errors raise a so called Signal, which can be handled by a handlerblock.
Especially with respect to instance creation, deletion and garbage collection, Smalltalk exceptions are very clean and easy to use.
All error conditions can be trapped and reacted upon by signal handlers. This includes situations which are fatal in other languages, such as stack overflow or array index bounds violations.

The most interresting classes are:

Please read Exception handling and signals for more details.
See List of signals for a partial list of signals, where they are created and what they mean.

Signal

Every exception condition is assigned a signal, which is raised when that condition is encountered. Therefore, a signal object can be thought of a way to identify a particular exception. Every class that raises a signal in one of its methods, creates these signal objects at class initialization time and keeps them in class variables for later. All classes provide access methods for these in their class protocol. For example, the signal raised upon division by zero is created in the Number class and can be accessed via "Number divisionByZeroSignal".
Typical use:

SignalSet

SignalSets represent a collection of Signals that can be handled in one handler as a group.

Exception

Instances of Exception are created when a signal is raised. They keep some information on where and why the exception occured and are passed as argument to the signal handler block. Within the handler block, execution can be continued in various ways, via messages to the exception object.
Typical uses:

Copyright © Claus Gittinger Development & Consulting, all rights reserved

(cg@ssw.de)