QuerySignal.st
author Claus Gittinger <cg@exept.de>
Thu, 07 Dec 1995 20:12:37 +0100
changeset 691 55730898da50
parent 580 03852d320a48
child 1248 04639edf1064
permissions -rw-r--r--
checkin from browser

"
 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.
"
!

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'!

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
!

isQuerySignal
    ^ true
! !

!QuerySignal class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/QuerySignal.st,v 1.5 1995-12-07 19:12:37 cg Exp $'
! !