|
Class: ExceptionHandlerSet
Object
|
+--Collection
|
+--Set
|
+--Dictionary
|
+--IdentityDictionary
|
+--ExceptionHandlerSet
- Package:
- stx:libbasic
- Category:
- Kernel-Exceptions
- Version:
- rev:
1.23
date: 2018/08/28 09:29:42
- user: cg
- file: ExceptionHandlerSet.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Stefan Vogel
An ExceptionHandlerSet allows a group of unrelated signals to be handled
by individual handlers - their evaluation is equivalent to a corresponding
number of nested signal handlers, but more efficient and
somwehat easier to program and read.
Exception
Signal
SignalSet
Compatibility-VW5.4
-
on: aSignalOrException handle: aHandler
-
add a handler for aSignal to the set
queries
-
accepts: aSignalOrExceptionClass
-
return true, if the receiver accepts the argument, aSignal.
(i.e. if any of the receiver's elements is aSignal or a parent of it).
-
exceptionHandlerFor: anException in: aContext
-
answer the exceptionHandler for anException from aContext.
-
handlerForSignal: signal
-
answer the handler block for signal
-
handlerForSignal: signal context: theContext originator: originator
-
answer the handler block for the signal from originator.
The block is retrieved from aContext.
Answer nil if the signal is not handled
-
handlerProtectedBlock: doBlock inContext: context
-
set the handlerProtectedBlock in context
-
handles: anException
-
return true, if the receiver handles the argument, anException.
(i.e. if any of the receiver's elements handles anException).
usage example(s):
(eachExceptionHandler handles:anException) ifTrue:[^ true]
|
save evaluation
-
handleDo: aBlock
-
evaluate the argument, aBlock.
If any of the signals in the receiver is raised during evaluation,
evaluate the handleBlock passing it an Exception argument.
The handler may decide how to react to the signal by sending
a corresponding message to the exception (see there).
If the signal is not raised, return the value of evaluating
aBlock.
-
handleDo: aBlock from: originator
-
evaluate the argument, aBlock.
If any of the signals in the receiver is raised during evaluation,
evaluate the handleBlock passing it an Exception argument.
The handler may decide how to react to the signal by sending
a corresponding message to the exception (see there).
If the signal is not raised, return the value of evaluating
aBlock.
setup
-
on: anExceptionHandlerOrHandlerCollection do: aHandlerBlock
-
add a handler for aSignal to the set.
anExceptionHandlerOrHandlerCollection may be a single exceptionHandler or
a Collection of exceptionHandlers (e.g. Array or SignalSet)
testing
-
isExceptionHandler
-
return true, if the receiver responds to the exception handler protocol,
especially to the #accepts: and #handles: messages
|h num|
h := ExceptionHandlerSet new.
h on:ZeroDivide
do:[:ex | 'division by zero' printCR. ex proceed].
h on:HaltInterrupt
do:[:ex | 'halt encountered ' printCR. ex proceed].
h on:DomainError
do:[:ex | 'domain error ' printCR. ex proceed].
h handleDo:[
num := 0.
'now dividing' printCR.
1 // num.
'now doing bad arcSin' printCR.
num := 50.
num arcSin.
'now halting' printCR.
self halt.
]
|
|h num|
h := ExceptionHandlerSet new.
h on:ZeroDivide
do:[:ex | 'division by zero' printCR. ex proceed].
h on:HaltInterrupt
do:[:ex | 'halt encountered ' printCR. ex proceed].
h on:DomainError
do:[:ex | 'domain error ' printCR. ex proceed].
[
num := 0.
'now dividing' printCR.
1 // num.
'now doing bad arcSin' printCR.
num := 50.
num arcSin.
'now halting' printCR.
self halt.
] valueWithExceptionHandler:h
|
|