Search code examples
exceptionsmalltalk

Nonboolean receiver--proceed for truth


I have a smalltalk method:

isInvalid
    |tmp|
    tmp := super isInvalid.
    tmp ifTrue: [^ True].
    ^ instanceVar isNil.

I am getting an exception: Unhandled exception: NonBoolean receiver--proceed for truth thrown on the assignment to temp. I am very sure that super isInvalid returns a Boolean object, so I think I am misunderstanding what this exception means. Does anybody else happen to know?


Solution

  • Long time ago, a worked in Smalltalk fulltime. Good to see that it is alive ...

    I see the following error in your code:

    • You use as a return value the value True, which is (in Smalltalk) the class with only value true.
    • You have to use instead the value true which is one of the (I think) predefined objects from the VM of Smalltalk which are true, false, nil.
    • An even better solution would be:

      ^ super isInvalid or: [instanceVar isNil]
      

      This replaces the whole body or your message, by the boolean expression (which is all the time true or false, no possibility for errors). (Thank's to Fabian for the correct method or:.)

    So use the right return value, and the error message will go away.

    By the way, the error message Unhandled exception: NonBoolean receiver--proceed for truth is some kind of debugging help, it allows you to proceed, so that you are able to develop faster ... Never saw that again in any other language ...