Signal.st
branchjv
changeset 18120 e3a375d5f6a8
parent 18066 89d51443ba6f
parent 16562 de9b98f4a494
child 18730 592c4cb8e98e
--- a/Signal.st	Tue Feb 04 21:09:59 2014 +0100
+++ b/Signal.st	Wed Apr 01 10:20:10 2015 +0100
@@ -1,6 +1,6 @@
 "
  COPYRIGHT (c) 1993 by Claus Gittinger
-              All Rights Reserved
+	      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
@@ -23,7 +23,7 @@
 copyright
 "
  COPYRIGHT (c) 1993 by Claus Gittinger
-              All Rights Reserved
+	      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
@@ -36,21 +36,21 @@
 
 documentation
 "
-    Note: 
-        The instance based Signal framework is being replaced by class based exceptions.
-        I.e. what used to be instances of Signal/QuerySignal is beeing
-        rewritten into subclasses of Exception/Error/Query and Warning.
+    Note:
+	The instance based Signal framework is being replaced by class based exceptions.
+	I.e. what used to be instances of Signal/QuerySignal is beeing
+	rewritten into subclasses of Exception/Error/Query and Warning.
 
-        Although the functionality is basically unchanged, the new
-        class based exceptions are easier to instanciate (no need for
-        creation in a classes initialize method), easier to use (no real
-        need for Signal-constant accessors) and allow for easier parameter
-        passing (not only a single parameter, but allows for individual
-        exception subclasses to add additional state).
+	Although the functionality is basically unchanged, the new
+	class based exceptions are easier to instanciate (no need for
+	creation in a classes initialize method), easier to use (no real
+	need for Signal-constant accessors) and allow for easier parameter
+	passing (not only a single parameter, but allows for individual
+	exception subclasses to add additional state).
 
-        However, the old Signal hierarchy will remain in existance, since it allows
-        funny instance-specific and anonymous exception handling schemes to be
-        implemented, which are hard to built using class-based exceptions.
+	However, the old Signal hierarchy will remain in existance, since it allows
+	funny instance-specific and anonymous exception handling schemes to be
+	implemented, which are hard to built using class-based exceptions.
 
     Signal and Exception provide a framework for exception handling.
 
@@ -58,10 +58,10 @@
     and associated with some abnormal event. Many signals are also
     created at startup time and reused.
 
-    When the event is raised (by Signal>>raise) the control will be either 
-    given to a debugger or - if a handler was defined - to the handler. 
-    The handler will get a description of what (and where) happened in an 
-    Exception object and can decide how to react on the situation (i.e. 
+    When the event is raised (by Signal>>raise) the control will be either
+    given to a debugger or - if a handler was defined - to the handler.
+    The handler will get a description of what (and where) happened in an
+    Exception object and can decide how to react on the situation (i.e.
     proceed, return or restart).
 
     There is also a companion class called SignalSet, which allows handling
@@ -78,8 +78,8 @@
     special:
 
     In addition to the nested catch & throw mechanism, signals can also be
-    used when no such handler scope exists. To support this, signals can be 
-    assigned a handlerBlock, which gets evaluated with the exception as argument 
+    used when no such handler scope exists. To support this, signals can be
+    assigned a handlerBlock, which gets evaluated with the exception as argument
     in case no handler was found (on the stack).
 
     If no handler was found (i.e. neither a handler context on the stack, nor
@@ -88,9 +88,9 @@
     This NoHandlerSignal can be handled just like any other signal.
     (therefore, it is possible to catch any error by catching NoHandlerSignal.
 
-    When the NoHandler signal is raised, and neither a handler-context, nor 
+    When the NoHandler signal is raised, and neither a handler-context, nor
     a handler block is defined for it, an emergencyHandler(-block) is evaluated.
-    This block is either provided by the current process 
+    This block is either provided by the current process
     (see Process>>emergencySignalHandler) or as a global default by the Exception
     class (see Exception>>emergencyHandler).
     The default emergencyHandlerBlock (from Exception) will bring up a debugger.
@@ -103,34 +103,34 @@
 
     [Instance variables:]
 
-        mayProceed      <Boolean>       hint for the debugger - program may 
-                                        proceed (currently not honored by the
-                                        debugger)
+	mayProceed      <Boolean>       hint for the debugger - program may
+					proceed (currently not honored by the
+					debugger)
 
-        notifierString  <String>        error message to be output 
+	notifierString  <String>        error message to be output
 
-        nameClass       <Class>         for the printOn-implementation; nameClass
-                                        is the class, to which message (below) 
-                                        should be sent to create the receiver.
+	nameClass       <Class>         for the printOn-implementation; nameClass
+					is the class, to which message (below)
+					should be sent to create the receiver.
 
-        message         <Symbol>        for the printOn-implementation; message
-                                        is the selector, which should be sent to 
-                                        nameClass (above) to create the receiver.
+	message         <Symbol>        for the printOn-implementation; message
+					is the selector, which should be sent to
+					nameClass (above) to create the receiver.
 
-        handlerBlock    <Block>         if nonNil, a 1-arg block to be 
-                                        evaluated when no handler context is 
-                                        found. The block gets the exception
-                                        object as argument. This will play the role
-                                        of an on-stack handler.
+	handlerBlock    <Block>         if nonNil, a 1-arg block to be
+					evaluated when no handler context is
+					found. The block gets the exception
+					object as argument. This will play the role
+					of an on-stack handler.
 
     [author:]
-        Claus Gittinger
+	Claus Gittinger
 
     [see also:]
-        GenericException 
-        SignalSet QuerySignal
-        Object
-        (``Exception handling and signals'': programming/exceptions.html)
+	GenericException
+	SignalSet QuerySignal
+	Object
+	(``Exception handling and signals'': programming/exceptions.html)
 "
 ! !
 
@@ -193,7 +193,9 @@
 !Signal methodsFor:'accessing'!
 
 creator
-    "return the creator of the exception (for exception protocol compatibilty)"
+    "return the creator of the exception (for exception protocol compatibilty).
+     For class based exceptions, that is the exception class;
+     for signals, that is the signal itself."
 
     ^ self
 !
@@ -207,14 +209,14 @@
 !
 
 handlerBlock
-    "return the handlerblock - if non-nil, this will be evaluated with the exception 
+    "return the handlerblock - if non-nil, this will be evaluated with the exception
      object as argument, if no #handle:do: context was found on the stack."
 
     ^ handlerBlock
 !
 
 handlerBlock:aOneArgBlock
-    "set the handlerblock - this will be evaluated with the exception 
+    "set the handlerblock - this will be evaluated with the exception
      object as argument, if no #handle:do: context was found on the stack."
 
     handlerBlock := aOneArgBlock
@@ -273,7 +275,7 @@
     ^ parent
 !
 
-parent:aSignal 
+parent:aSignal
     "set the parent-signal of the receiver."
 
     parent := aSignal
@@ -349,11 +351,11 @@
     |s|
 
     notifierString isNil ifTrue:[
-        ^ parent description
+	^ parent description
     ].
     s := notifierString asString.
     (s startsWith:Character space) ifTrue:[
-        ^ parent description, s
+	^ parent description, s
     ].
     ^ s
 
@@ -365,7 +367,7 @@
 !
 
 descriptionForDebugger
-    "return the description string of the signal which is used in the 
+    "return the description string of the signal which is used in the
      debugger title area"
 
     ^ self description.
@@ -375,14 +377,14 @@
     "append a printed representation of the receiver on aStream"
 
     nameClass notNil ifTrue:[
-        nameClass isBehavior ifTrue:[
-            aStream nextPutAll:nameClass name.
-        ] ifFalse:[
-            nameClass printOn:aStream.
-        ].
-        aStream space.
-        aStream nextPutAll:message.
-        ^ self
+	nameClass isBehavior ifTrue:[
+	    aStream nextPutAll:nameClass name.
+	] ifFalse:[
+	    nameClass printOn:aStream.
+	].
+	aStream space.
+	aStream nextPutAll:message.
+	^ self
     ].
     ^ super printOn:aStream
 ! !
@@ -400,8 +402,8 @@
 
     s := aSignal parent.
     [s notNil] whileTrue:[
-        self == s ifTrue:[^ true].
-        s := s parent
+	self == s ifTrue:[^ true].
+	s := s parent
     ].
     ^ false
 
@@ -432,9 +434,9 @@
 
     (theContext selector ~~ #'handle:from:do:'
      or:[(theContext argAt:2) == originator]) ifTrue:[
-        (self == signal or:[self accepts:signal]) ifTrue:[
-            ^ (theContext argAt:1) ? [nil]
-        ]
+	(self == signal or:[self accepts:signal]) ifTrue:[
+	    ^ (theContext argAt:1) ? [nil]
+	]
     ].
 
     ^ nil
@@ -446,9 +448,9 @@
     "set the handlerProtectedBlock in context"
 
     context selector == #handle:do: ifTrue:[
-        context argAt:2 put:doBlock.
+	context argAt:2 put:doBlock.
     ] ifFalse:[context selector == #handle:from:do: ifTrue:[
-        context argAt:3 put:doBlock.
+	context argAt:3 put:doBlock.
     ]].
 
 
@@ -467,7 +469,7 @@
     anException isNotification ifTrue:[^ false].  "speed up queries by not traversing the parent chain"
 
     [(signal := signal parent) notNil] whileTrue:[
-        self == signal ifTrue:[^ true].
+	self == signal ifTrue:[^ true].
     ].
     ^ false
 !
@@ -516,7 +518,7 @@
 !
 
 isHandledIn:aContext
-    "return true, if there is a handler for the receiver signal in the 
+    "return true, if there is a handler for the receiver signal in the
      contextChain starting with aContext."
 
     ^ GenericException exception:self isHandledIn:aContext
@@ -539,7 +541,7 @@
     <context: #return>
 
     ^ self newException
-        raiseIn:thisContext sender
+	raiseIn:thisContext sender
 
     "Created: / 23-07-1999 / 14:07:17 / stefan"
     "Modified: / 10-08-2010 / 09:58:57 / cg"
@@ -552,7 +554,7 @@
     <context: #return>
 
     ^ self newException
-        raiseErrorString:aString in:thisContext sender
+	raiseErrorString:aString in:thisContext sender
 
     "Created: / 23-07-1999 / 14:07:33 / stefan"
     "Modified: / 10-08-2010 / 09:59:22 / cg"
@@ -565,21 +567,21 @@
     <context: #return>
 
     ^ self newException
-        raiseErrorString:aString in:aContext
+	raiseErrorString:aString in:aContext
 
     "Created: / 23-07-1999 / 14:07:33 / stefan"
     "Modified: / 10-08-2010 / 09:59:58 / cg"
 !
 
-raiseFrom:something 
+raiseFrom:something
     "raise a signal nonproceedable.
      The argument, something is passed both as parameter and originator."
-    
+
     <context: #return>
 
     ^ (self newException
-            suspendedContext:(thisContext sender) parameter:something originator:something)
-        raise
+	    suspendedContext:(thisContext sender) parameter:something originator:something)
+	raise
 
     "Created: / 23-07-1999 / 14:07:59 / stefan"
     "Modified: / 10-08-2010 / 09:58:36 / cg"
@@ -592,7 +594,7 @@
     <context: #return>
 
     ^ self newException
-        raiseRequestIn:thisContext sender
+	raiseRequestIn:thisContext sender
 
     "Created: / 23-07-1999 / 14:08:24 / stefan"
     "Modified: / 10-08-2010 / 10:00:13 / cg"
@@ -605,20 +607,20 @@
     <context: #return>
 
     ^ self newException
-        raiseRequestErrorString:aString in:thisContext sender
+	raiseRequestErrorString:aString in:thisContext sender
 
     "Modified: / 10-08-2010 / 10:00:40 / cg"
 !
 
-raiseRequestFrom:something 
+raiseRequestFrom:something
     "raise a signal proceedable.
      The argument, something is passed both as parameter and originator."
-    
+
     <context: #return>
 
     ^ (self newException
-        suspendedContext:(thisContext sender) parameter:something originator:something)
-        raiseRequest
+	suspendedContext:(thisContext sender) parameter:something originator:something)
+	raiseRequest
 
     "Modified: / 2.5.1996 / 16:36:38 / cg"
     "Modified: / 5.3.1998 / 16:52:46 / stefan"
@@ -632,7 +634,7 @@
     <context: #return>
 
     ^ self newException
-        raiseRequestWith:aParameter in:thisContext sender
+	raiseRequestWith:aParameter in:thisContext sender
 
     "Created: / 23-07-1999 / 14:08:48 / stefan"
     "Modified: / 10-08-2010 / 10:01:00 / cg"
@@ -645,7 +647,7 @@
     <context: #return>
 
     ^ self newException
-        raiseRequestWith:aParameter errorString:aString in:thisContext sender
+	raiseRequestWith:aParameter errorString:aString in:thisContext sender
 
     "Created: / 23-07-1999 / 14:08:57 / stefan"
     "Modified: / 10-08-2010 / 10:01:38 / cg"
@@ -660,7 +662,7 @@
     <context: #return>
 
     ^ self newException
-        raiseRequestWith:aParameter errorString:aString in:aContext
+	raiseRequestWith:aParameter errorString:aString in:aContext
 
     "Created: / 23-07-1999 / 14:09:07 / stefan"
     "Modified: / 10-08-2010 / 10:02:08 / cg"
@@ -674,7 +676,7 @@
     <context: #return>
 
     ^ self newException
-        raiseRequestWith:aParameter in:aContext
+	raiseRequestWith:aParameter in:aContext
 
     "Modified: / 10-08-2010 / 10:02:26 / cg"
 !
@@ -686,8 +688,8 @@
     <context: #return>
 
     ^ (self newException
-        suspendedContext:thisContext sender)
-        raiseSignal
+	suspendedContext:thisContext sender)
+	raiseSignal
 
     "Modified: / 10.11.2001 / 15:13:34 / cg"
 !
@@ -699,8 +701,8 @@
     <context: #return>
 
     ^ (self newException
-        suspendedContext:(thisContext sender) errorString:errorMessage)
-        raiseSignal.
+	suspendedContext:(thisContext sender) errorString:errorMessage)
+	raiseSignal.
 
     "Modified: / 07-08-2004 / 19:24:00 / stefan"
 !
@@ -712,8 +714,8 @@
     <context: #return>
 
     ^ (self newException
-        suspendedContext:(thisContext sender) parameter:aParameter errorString:errorMessage) 
-        raiseSignal.
+	suspendedContext:(thisContext sender) parameter:aParameter errorString:errorMessage)
+	raiseSignal.
 
     "Modified: / 07-08-2004 / 19:10:40 / stefan"
 !
@@ -725,8 +727,8 @@
     <context: #return>
 
     ^ (self newException
-        suspendedContext:(thisContext sender) errorString:aString)
-        raiseSignal.
+	suspendedContext:(thisContext sender) errorString:aString)
+	raiseSignal.
 !
 
 raiseSignalWith:aParameter
@@ -736,8 +738,8 @@
     <context: #return>
 
     ^ (self newException
-        suspendedContext:(thisContext sender) parameter:aParameter)
-        raiseSignal.
+	suspendedContext:(thisContext sender) parameter:aParameter)
+	raiseSignal.
 !
 
 raiseSignalWith:aParameter errorString:aString
@@ -748,8 +750,8 @@
     <context: #return>
 
     ^ (self newException
-        suspendedContext:(thisContext sender) parameter:aParameter errorString:aString)
-        raiseSignal.
+	suspendedContext:(thisContext sender) parameter:aParameter errorString:aString)
+	raiseSignal.
 !
 
 raiseWith:aParameter
@@ -759,7 +761,7 @@
     <context: #return>
 
     ^ self newException
-        raiseWith:aParameter in:thisContext sender
+	raiseWith:aParameter in:thisContext sender
 
     "Created: / 23-07-1999 / 14:09:27 / stefan"
     "Modified: / 10-08-2010 / 10:02:51 / cg"
@@ -773,7 +775,7 @@
     <context: #return>
 
     ^ self newException
-        raiseWith:aParameter errorString:aString in:thisContext sender
+	raiseWith:aParameter errorString:aString in:thisContext sender
 
     "Created: / 23-07-1999 / 14:09:36 / stefan"
     "Modified: / 10-08-2010 / 10:03:29 / cg"
@@ -789,7 +791,7 @@
     <context: #return>
 
     ^ self newException
-        raiseWith:aParameter errorString:aString in:aContext
+	raiseWith:aParameter errorString:aString in:aContext
 
     "Created: / 23-07-1999 / 14:09:46 / stefan"
     "Modified: / 10-08-2010 / 10:03:19 / cg"
@@ -804,7 +806,7 @@
     <context: #return>
 
     ^ self newException
-        raiseWith:aParameter in:aContext
+	raiseWith:aParameter in:aContext
 
     "Modified: / 10-08-2010 / 10:03:05 / cg"
 ! !
@@ -814,7 +816,7 @@
 catch:aBlock
     "evaluate the argument, aBlock.
      If the receiver-signal is raised during evaluation, abort
-     the evaluation and return true; otherwise return false. 
+     the evaluation and return true; otherwise return false.
      This is the catch & throw mechanism found in other languages,
      where the returned value indicates if an exception occured."
 
@@ -826,7 +828,7 @@
 
     "
      Object messageNotUnderstoodSignal catch:[
-        123 size open   
+	123 size open
      ]
     "
 !
@@ -839,27 +841,27 @@
      If the signal is raised multiple times, only the first raises parameter is remembered,
      and only a single raise is performed after the blocks evaluation.
 
-     Deferring makes sense for some signals, such as UserInterrupt or AbortSignal, 
-     which must occasionally be delayed temporarily until a save place is reached 
+     Deferring makes sense for some signals, such as UserInterrupt or AbortSignal,
+     which must occasionally be delayed temporarily until a save place is reached
      (especially when packages are sent across a communication channel, and you dont want
       partial packages to be generated by user interruptions)."
 
-    |coughtException result|
+    |caughtException result|
 
     self handle:[:ex |
-        coughtException isNil ifTrue:[
-            coughtException := ex.
-        ].
-        ex proceedWith:nil
+	caughtException isNil ifTrue:[
+	    caughtException := ex.
+	].
+	ex proceedWith:nil
     ] do:[
-        result := aBlock value.
+	result := aBlock value.
     ].
-    coughtException notNil ifTrue:[
-        coughtException suspendedContext:thisContext.
+    caughtException notNil ifTrue:[
+	caughtException suspendedContext:thisContext.
 
-        "/ the signal was raised during the execution of aBlock above. 
-        "/ Raise it now (delayed).
-        coughtException raiseSignal
+	"/ the signal was raised during the execution of aBlock above.
+	"/ Raise it now (delayed).
+	caughtException raiseSignal
     ].
     ^ result
 
@@ -868,7 +870,7 @@
 
       s := Signal new mayProceed:true.
       s deferAfter:[
-         s raiseRequestWith:'hello' errorString:'eeee'
+	 s raiseRequestWith:'hello' errorString:'eeee'
       ]
      "
 !
@@ -876,15 +878,15 @@
 evaluate:aBlock ifRaised:exceptionValue
     "evaluate the argument, aBlock and return its value.
      If the receiver-signal is raised during evaluation, abort
-     the evaluation and return the value from exceptionValue. 
+     the evaluation and return the value from exceptionValue.
      This is similar to the catch & throw mechanism found in other languages"
 
     ^ self handle:[:ex | exceptionValue value] do:aBlock.
 
     "
-     Object messageNotUnderstoodSignal 
-        evaluate:[ 123 size open ]
-        ifRaised:[ self halt ]
+     Object messageNotUnderstoodSignal
+	evaluate:[ 123 size open ]
+	ifRaised:[ self halt ]
     "
 !
 
@@ -905,10 +907,10 @@
 
     "
      Object messageNotUnderstoodSignal handle:[:ex |
-        'oops' printNL.
-        ex return
+	'oops' printNL.
+	ex return
      ] do:[
-        123 size open   
+	123 size open
      ]
     "
 
@@ -917,10 +919,10 @@
 
      num := 0.
      Number divisionByZeroSignal handle:[:ex |
-        'oops' printNL.
-        ex return
+	'oops' printNL.
+	ex return
      ] do:[
-        123 / num   
+	123 / num
      ]
     "
 
@@ -950,18 +952,18 @@
 
      o1 := 123.
      o2 := nil.
-     Object messageNotUnderstoodSignal 
-         handle:
-              [:ex |
-                  'oops' printNL.
-                  ex proceed
-              ] 
-         from:o1
-         do:
-              [
-                  o1 open.
-                  o2 open
-              ]
+     Object messageNotUnderstoodSignal
+	 handle:
+	      [:ex |
+		  'oops' printNL.
+		  ex proceed
+	      ]
+	 from:o1
+	 do:
+	      [
+		  o1 open.
+		  o2 open
+	      ]
     "
 
     "Modified: / 25.7.1999 / 19:43:40 / stefan"
@@ -969,7 +971,7 @@
 
 ignoreIn:aBlock
     "evaluate the argument, aBlock.
-     Ignore the receiver-signal during evaluation - i.e. simply continue. 
+     Ignore the receiver-signal during evaluation - i.e. simply continue.
      This makes only sense for some signals, such as UserInterrupt
      or AbortSignal, because continuing after an exception without any cleanup
      often leads to followup-errors."
@@ -978,7 +980,7 @@
 
      "
       Object messageNotUnderstoodSignal ignoreIn:[
-         123 size open   
+	 123 size open
       ]
      "
 ! !
@@ -986,10 +988,9 @@
 !Signal class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Signal.st,v 1.113 2013-06-05 11:25:09 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Signal.st,v 1.115 2014-06-10 10:20:23 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Signal.st,v 1.113 2013-06-05 11:25:09 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Signal.st,v 1.115 2014-06-10 10:20:23 cg Exp $'
 ! !
-