eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ExceptionHandlerSet':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: ExceptionHandlerSet


Inheritance:

   Object
   |
   +--Collection
      |
      +--Set
         |
         +--Dictionary
            |
            +--IdentityDictionary
               |
               +--ExceptionHandlerSet

Package:
stx:libbasic
Category:
Kernel-Exceptions
Version:
rev: 1.25 date: 2021/01/20 14:25:11
user: cg
file: ExceptionHandlerSet.st directory: libbasic
module: stx stc-classLibrary: libbasic

Description:


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.

copyright

COPYRIGHT (c) 1999 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Instance protocol:

Compatibility-VW5.4
o  on: aSignalOrException handle: aHandler
add a handler for aSignal to the set

queries
o  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).

o  exceptionHandlerFor: anException in: aContext
answer the exceptionHandler for anException from aContext.

o  handlerForSignal: signal
answer the handler block for signal

o  handlerForSignal: exceptionCreator 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

o  handlerProtectedBlock: doBlock inContext: context
set the handlerProtectedBlock in context

o  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
o  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.

Usage example(s):

    |h num|

    h := ExceptionHandlerSet new.
    h on:(Number divisionByZeroSignal)
      handle:[:ex | 'division by zero' printNL. ex proceed].

    h on:(Object haltSignal)
      handle:[:ex | 'halt encountered ' printNL. ex proceed].

    h on:(Float domainErrorSignal)
      handle:[:ex | 'domain error  ' printNL. ex proceed].

    h handleDo:[
       num := 0.

       'now dividing' printNL.
       1 // num.

       'now doing bad arcSin' printNL.
       num := 50.
       num arcSin.

       'now halting' printNL.
       self halt.
    ]

o  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.

Usage example(s):

    |h num|

    h := ExceptionHandlerSet new.
    h on:(Number divisionByZeroSignal)
      handle:[:ex | 'division by zero' printNL. ex proceed].

    h on:(Object haltSignal)
      handle:[:ex | 'halt encountered ' printNL. ex proceed].

    h on:(Float domainErrorSignal)
      handle:[:ex | 'domain error  ' printNL. ex proceed].

    h handleDo:[
       'now halting' printNL.
       self halt.

       'the following exceptions are not handled.
        A debugger is opened' printNL.

       'now dividing' printNL.
       num := 0.
       1 // num.

       'now doing bad arcSin' printNL.
       num := 50.
       num arcSin.
    ] from:self

setup
o  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
o  isExceptionHandler
return true, if the receiver responds to the exception handler protocol,
especially to the #accepts: and #handles: messages


Examples:


         |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


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Tue, 22 Oct 2024 14:26:45 GMT