ProceedingNotification.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 22941 37932970b277
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...

"{ Encoding: utf8 }"

"
 COPYRIGHT (c) 2013 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' }"

"{ NameSpace: Smalltalk }"

Notification subclass:#ProceedingNotification
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Kernel-Exceptions'
!

!ProceedingNotification class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2013 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
"    
    A ProceedingNotification behaves much like a regular notification,
    in that if no handler is present, execution proceeds after the raise.
    However, iff a handler simply falls through, the exception is proceeded.
    The handler is still free to choose for an explicit action (return/reject).

    [author:]
        Claus Gittinger

    [see also:]
        Exception Query Notification
"
!

examples 
"
  Notice, that in contrast to a regular Notification, the execution proceeds after the Notification:
                                                                        [exBegin]
    |zero|

    zero := 0.
    ProceedingNotification handle:[:n |
        Transcript showCR:'h: ' , n description.
    ] do:[
        Error handle:[:ex |
            Transcript showCR:'some error: ' , ex errorString.
            ex proceed
        ] do:[
            [
                |answer|

                1 // zero.  'an error which is caught in the handler'.
                answer := ProceedingNotification notify:'hello world'.
                Transcript show:'after notification: '; showCR:answer.
            ] value
        ]
    ].
                                                                        [exEnd]

  however, if the handler returns, this is not the case:
                                                                        [exBegin]
    |zero|

    zero := 0.
    ProceedingNotification handle:[:n |
        Transcript showCR:'h: ' , n description.
        n return.
    ] do:[
        Error handle:[:ex |
            Transcript showCR:'some error: ' , ex errorString.
            ex proceed
        ] do:[
            [
                |answer|

                1 // zero.  'an error which is caught in the handler'.
                answer := ProceedingNotification notify:'hello world'.
                Transcript show:'after notification 1: '; showCR:answer.
            ] value
        ]
    ].
                                                                        [exEnd]
"
! !

!ProceedingNotification class methodsFor:'initialization'!

initialize

    NotifierString := 'Notification:'
! !

!ProceedingNotification methodsFor:'default actions'!

doCallHandler:aHandlerBlock
    "call the handler proper - if the handler falls through, proceed with the handler's value.
     - an extra method is needed to have a raise-marked context around.
       (see implementation of #reject and #proceed)."

    <context: #return>
    <exception: #raise>

    |val|

    (aHandlerBlock isBlockWithArgumentCount:1) ifTrue:[
        "1-arg handler - pass myself as exception argument"
        val := aHandlerBlock value:self.
    ] ifFalse:[
        "0-arg handler or any object - not interested in the exception argument"
        val := aHandlerBlock value
    ].

    "handler fall through - this is different here!!"
    self proceedWith:val

    "Modified (format): / 18-03-2017 / 18:27:22 / stefan"
! !

!ProceedingNotification class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !


ProceedingNotification initialize!