"
COPYRIGHT (c) 2002 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.
"
"{ Package: 'stx:libbasic' }"
Notification subclass:#Query
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'Kernel-Exceptions'
!
!Query class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 2002 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.
"
!
documentation
"
Query is an abstract superclass for queries.
A query is an exception which by default proceeds if unhandled and returns
a default value.
As a class based reimplementation, it replaces and obsoletes the old
QuerySignal instance based mechanism.
Note:
Query does not add/refine any functionality from its superclass.
It exists for the more descriptive class name only.
[author:]
Claus Gittinger
[see also:]
Warning Signal QuerySignal
"
!
examples
"
[exBegin]
Query answer:'hello'
do:[
Transcript showCR:(Query query)
]
[exEnd]
an up-query from a deeply nested operation to a higher level:
the example below demonstrates that a Query is not an Error
(i.e. the Error-handler does not interfere with Queries)
[exBegin]
|zero|
zero := 0.
Query handle:[:ex |
Transcript showCR:'query'.
ex proceedWith:true
] do:[
'nesting'.
[
[
Error handle:[:ex |
Transcript showCR:'some error: ' , ex errorString.
ex proceed
] do:[
[
1 // zero. 'an error which is caught in the handler'.
(Query query) == true ifTrue:[
Transcript showCR:'query says: ok'.
] ifFalse:[
Transcript showCR:'query says: no'
]
] value
]
] value
] value
]
[exEnd]
for lazy typists, a more compact interface for query-answerign
is also provided (which is also easier to read):
[exBegin]
Query answer:true do:[
'nesting'.
[
[
(Query query) == true ifTrue:[
Transcript showCR:'query says: ok'.
] ifFalse:[
Transcript showCR:'query says: no'
]
] value
] value
]
[exEnd]
an up-query from a deeply nested operation, for which there
is no handler:
(notice, this would not work with normal signals, which would raise
another unhandled exception-exception;
also notice the == check #raise's return value being true,
instead of a simple ifTrue; this handles a nil-value from
the unhandled query)
[exBegin]
|zero|
zero := 0.
[
'nesting'.
[
[
Error handle:[:ex |
Transcript showCR:'some error: ' , ex errorString.
ex proceed
] do:[
[
1 // zero. 'an error which is caught in the handler'.
(Query raise) == true ifTrue:[
Transcript showCR:'query says: ok'.
] ifFalse:[
Transcript showCR:'query says: no'
]
] value
]
] value
] value
] value
[exEnd]
counter-example, just to show that things would not work this way
with regular signals:
[exBegin]
|signal|
signal := Signal new.
'nesting deeply'.
[
[
[
[
[
(signal raise) == true ifTrue:[
Transcript showCR:'query says: ok'.
] ifFalse:[
Transcript showCR:'query says: no'
]
] value
] value
] value
] value
] value
[exEnd]
except, by handling the unhandled exception
(but we think, that querySignals are easier to use and
better document the intent):
[exBegin]
|signal|
signal := Signal new.
'nesting deeply'.
[
[
[
[
[
Signal noHandlerSignal handle:[:ex |
ex proceedWith:nil
] do:[
(signal raise) == true ifTrue:[
Transcript showCR:'query says: ok'.
] ifFalse:[
Transcript showCR:'query says: no'
]
]
] value
] value
] value
] value
] value
[exEnd]
"
! !
!Query class methodsFor:'initialization'!
initialize
NotifierString := 'Query'.
"
self initialize
"
! !
Query initialize!