How to find which was the wrong message in a Messa

2019-05-10 13:41发布

问题:

I want to find the name of the message that triggered the MNU , how do I do that ?

For example if I do

Transcript explode . 

This will trigger a MNU because method explode does not exist but how do I find that the name of the message that triggered MNU is "explode" ?

回答1:

If I DoIt that, I get a debugger. The title there is

MessageNotUnderstood: ThreadSafeTranscript>>explode

When I select the first element, I get to see the doesNotUnderstand: aMessage, where aMessage is the message



回答2:

Try this:

[Transcript explode] on: MessageNotUnderstood do: [:ex| ex message selector]

The exception's message is an instance of Message. It understands selector arguments etc.

Remember that the exception is an epiphenomenon. The VM actually sends doesNotUnderstand: aMessage when a message is not understood, and the doesNotUnderstand: method in Object raises the exception. The argument to doesNotUnderstand: is a message, and is of curse the same as that in the exception. That means you can implement your own doesNotUnderstand: message in your own class if you have special requirements.