GenericException.st
changeset 19776 31fa179f48bf
parent 19717 78a27db0fdb6
child 19811 65fec19facb0
child 20089 2468c0711e9a
equal deleted inserted replaced
19775:cfffb072d9a3 19776:31fa179f48bf
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 1993 by Claus Gittinger
     4  COPYRIGHT (c) 1993 by Claus Gittinger
     3 	      All Rights Reserved
     5 	      All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
   548 
   550 
   549     "Created: / 23-07-1999 / 14:07:17 / stefan"
   551     "Created: / 23-07-1999 / 14:07:17 / stefan"
   550     "Modified: / 10-08-2010 / 09:30:42 / cg"
   552     "Modified: / 10-08-2010 / 09:30:42 / cg"
   551 !
   553 !
   552 
   554 
       
   555 raiseAsQuery
       
   556     "utility to avoid code duplication.
       
   557      raise the exception as a query. This means, that if it is unhandled,
       
   558      a default value is returned (i.e. an implicit resume).
       
   559      Return the handler's value (if there is one), or the default value, if not.
       
   560      Invoking the handler is exactly the functionality of Signal>>raiseRequest,
       
   561      but we can do it faster here (avoiding the construction of an exception instance)."
       
   562 
       
   563     |con signal ret|
       
   564 
       
   565     self isQuerySignal ifFalse:[ self error:'this may only be used by queries' ].
       
   566 
       
   567     con := Context findFirstSpecialHandle:true raise:false.
       
   568     [con notNil] whileTrue:[
       
   569         (con selector == #answer:do:) ifTrue:[ 
       
   570             signal := con receiver.
       
   571             signal == self ifTrue:[
       
   572                 ret := con argAt:1.
       
   573                 con := nil.
       
   574                 ^ ret
       
   575             ].
       
   576             signal isNil ifTrue:[
       
   577                 self error:'nil receiver in #answer:do: - send'.
       
   578             ].
       
   579             (signal accepts:self) ifTrue:[
       
   580                 ret := con argAt:1.
       
   581                 con := nil.
       
   582                 ^ ret
       
   583             ].
       
   584         ] ifFalse:[
       
   585             "ask the the receiver of the #handle:do: or #on:do: or whatever- message for the handler.
       
   586              nil is returned, if the signal is not accepted"
       
   587             |r|
       
   588             r := con receiver.     "receiver of #handle:do: or #on:do:"
       
   589             (r notNil and:[(r handlerForSignal:self
       
   590                                  context:con
       
   591                                  originator:thisContext sender homeReceiver) notNil]
       
   592             ) ifTrue:[
       
   593                 "there is another handler block, maybe it will return the answer.
       
   594                  Call it via raiseRequest"
       
   595                 con := nil.
       
   596                 ^ here raiseRequest  "/ <- notice the here, to avoid recursion due
       
   597                                      "/ to redefined raiseRequest in Query
       
   598             ].
       
   599         ].
       
   600         con := con findSpecialHandle:true raise:false.
       
   601     ].
       
   602 
       
   603     "/ no handler found - return the default value
       
   604     ^ self defaultAnswer
       
   605 
       
   606     "Modified: / 15-06-1998 / 21:27:37 / cg"
       
   607     "Modified: / 25-07-1999 / 23:15:16 / stefan"
       
   608     "Modified: / 11-03-2015 / 11:26:45 / sr"
       
   609 !
       
   610 
   553 raiseErrorString:aString
   611 raiseErrorString:aString
   554     "raise a signal nonproceedable.
   612     "raise a signal nonproceedable.
   555      The argument is used as messageText."
   613      The argument is used as messageText."
   556 
   614 
   557     <context: #return>
   615     <context: #return>