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:
Number
class and can be accessed via "Number divisionByZeroSignal"
.
Number arithmeticSignal
Number divisionByZeroSignal
Object errorSignal
aSignal handle:[ ... handlerBlock ...] do:[ ...some computation ... ]
aSignal catch:[ ...some computation ... ]
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.
aSignal handle:[:exception |
...
exception return
]
aSignal handle:[:exception |
...
exception restart
]
aSignal handle:[:exception |
...
exception resume
]
anException signal
anException errorString
anException handlerContext
anException suspendedContext
Copyright © Claus Gittinger Development & Consulting, all rights reserved
(cg@ssw.de)