QuerySignal.st
author Claus Gittinger <cg@exept.de>
Mon, 20 Nov 1995 14:18:04 +0100
changeset 580 03852d320a48
parent 530 07d0bce293c9
child 691 55730898da50
permissions -rw-r--r--
commentary

"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      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.
"

Signal subclass:#QuerySignal
	 instanceVariableNames:''
	 classVariableNames:''
	 poolDictionaries:''
	 category:'Kernel-Exceptions'
!

!QuerySignal class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      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.
"
!

version
    ^ '$Header: /cvs/stx/stx/libbasic/QuerySignal.st,v 1.4 1995-11-20 13:18:04 cg Exp $'
!

documentation
"
    QuerySignals are like signals, except that they are not accepted
    by handlers for ordinary signals.
    I.e. a signal handler for a normal signal will not handle a query
    signal. Thus, these bypass anySignal handlers.
    Also, using a QuerySignal helps in documenting the intended use of these signals.

    They can be used to implement up-Queries via signals even if intermediate
    errorSignal handlers are present (which is no possible with ordinary signals).
"
!

examples 
"
    an up-query from a deeply nested operation to a higher level:

	|querySignal zero|

	zero := 0.
	querySignal := QuerySignal new.
	querySignal handle:[:ex |
	    ex proceedWith:true
	] do:[
	    'nexting'.
	    [
		[
		    Object errorSignal handle:[:ex |
			ex proceed
		    ] do:[
			[
			    1 // zero.  'a cought error'.
			    (querySignal raise) ifTrue:[
				Transcript showCr:'query says: ok'.
			     ] ifFalse:[
				Transcript showCr:'query says: no'
			     ]
			] value
		    ]
		] value
	    ] value
	]
"
! !

!QuerySignal methodsFor:'queries'!

isQuerySignal
    ^ true
!

accepts:aSignal
    "return true, if the receiver accepts the argument, aSignal.
     (i.e. the receiver is aSignal or a parent of it). False otherwise."

    |s|

    aSignal isQuerySignal ifFalse:[^ false].

    s := aSignal.
    [s notNil] whileTrue:[
	self == s ifTrue:[^ true].
	s := s parent
    ].
    ^ false
! !