How to find which was the wrong message in a Message Not Understood message?

和自甴很熟 提交于 2019-12-22 10:49:54

问题


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.



来源:https://stackoverflow.com/questions/24831610/how-to-find-which-was-the-wrong-message-in-a-message-not-understood-message

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!