MessageNotUnderstood.st
author Stefan Vogel <sv@exept.de>
Thu, 16 Apr 2015 18:28:45 +0200
branchexpecco_2_7_5
changeset 18220 361e98951d47
parent 16414 718569261384
child 18120 e3a375d5f6a8
child 18290 5ea0b888d79d
permissions -rw-r--r--
Add methods for backward compatibilty with older sublasses

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

ProceedableError subclass:#MessageNotUnderstood
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Kernel-Exceptions-Errors'
!

!MessageNotUnderstood class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2001 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
"
    raised when a message is sent to an object, which is not understood
    by the receiver, and the message was not handled by a class specific
    doesNotUnderstand: handler.
"
! !

!MessageNotUnderstood class methodsFor:'initialization'!

initialize
    NotifierString := 'message not understood'.

    "
     self initialize
    "
! !

!MessageNotUnderstood class methodsFor:'save evaluation'!

ignoreNotUnderstoodOf:aSelector in:aBlock
    "evaluate aBlock; if a messageNotUnderstood occurs,
     for which the message was aSelector, ignore the error
     and return.
     Other selector errors lead into the debugger.
     If no error occurs, return the blocks value"

    ^ self handle:[:ex |
        ex selector == aSelector ifFalse:[
            ex reject
        ]
    ] do:aBlock.
!

ignoreNotUnderstoodOfAny:aCollectionOfSelectors in:aBlock
    "evaluate aBlock; if a messageNotUnderstood occurs,
     for which the message was any in aCollectionOfSelectors, ignore the error
     and return.
     Other selector errors lead into the debugger.
     If no error occurs, return the blocks value"

    ^ self handle:[:ex |
        (aCollectionOfSelectors includesIdentical:ex selector) ifFalse:[
            ex reject
        ]
    ] do:aBlock.
! !

!MessageNotUnderstood methodsFor:'accessing'!

message
    ^ parameter

    "
     [
        123 perform:#foo
     ] on:MessageNotUnderstood do:[:ex |
        Transcript show:'message object: '; showCR:ex message storeString.
        Transcript show:'receiver: '; showCR:ex receiver storeString.
        Transcript show:'selector: '; showCR:ex message selector storeString.
        Transcript show:'arguments: '; showCR:ex message arguments storeString.
     ]
    "
!

receiver
    ^ originator

    "
     [
        123 perform:#foo
     ] on:MessageNotUnderstood do:[:ex |
        Transcript showCR:ex receiver
     ]
    "
!

selector
    ^ parameter selector

    "
     [
        123 perform:#foo
     ] on:MessageNotUnderstood do:[:ex |
        Transcript show:'selector: '; showCR:ex selector storeString.
     ]
    "
! !

!MessageNotUnderstood methodsFor:'printing & storing'!

description
    "the human readable description of the exception"

    |cls sel description|

    "extract the class that should have implemented the message.
     (in case of a super-send, this is not the receiver's class)"
    suspendedContext notNil ifTrue:[
        cls := suspendedContext searchClass.
        suspendedContext sender notNil ifTrue:[
            cls := suspendedContext sender searchClass.
        ].
    ].
    cls isNil ifTrue:[
        cls := self receiver class.
    ].
    cls notNil ifTrue:[
        "displayString is better than 'cls name',
         since it appends (obsolete) for outdated classes.
         (this happens if you send messages to old instances
          after changing a classes definition)"

        description := cls displayString.
        description isString ifFalse:[
            description := '(** ???-class **)'
        ].
    ] ifFalse:[    
        description := '(** nil-class **)'
    ].
    sel := self selector.
    sel class == Symbol ifTrue:[
        description := description , ' does not understand: ' , sel storeString.
        "/ description := sel, ' not understood by ' ,  description.
    ] ifFalse:[
        "a non-symbol selector may happen when things go mad in a primitive, 
         or a method has been called by #perform: or #valueWithReceiver: with a wrong arg."

        description := description , ' does not understand nonSymbol: ' , sel printString.
        "/ description := sel printString, ' (nonSymbol) not understood by ' ,  description.
    ].

    ^ description


    "
        2 foo:3
        2 perform:55
        nil // 2
    "

    "Modified: / 19-08-2010 / 15:33:03 / cg"
! !

!MessageNotUnderstood class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/MessageNotUnderstood.st,v 1.13 2014-05-09 13:06:50 cg Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libbasic/MessageNotUnderstood.st,v 1.13 2014-05-09 13:06:50 cg Exp $'
! !


MessageNotUnderstood initialize!