. .


ST 4U 234: Message Swallowing MNU

December 21, 2012 12:49:44.511

Today's Smalltalk 4 You looks at the a cool - but dangerous - thing in Smalltalk - the ability to handle messages that are not understood. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:


If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

One of the things you'll run across in Smalltalk is the ability to handle a "Message Not Understood" exception. While there are uses for such handling (proxy development, for example) - it's often quite dangerous. Even more dangerous is implementing a catchall #doesNotUnderstand: message to your class - it can simply swallow all such MNU exceptions, leading to very bizarre behavior. Consider a simple Counter class with a one up counter, and an #addOne (but no #subtractOne) method, and this implementation:

doesNotUnderstand: aMessage
	Transcript show: 'Not Understood: ', aMessage selector printString; cr

It seems simple enough, but consider the case where that counter is meaningful. A user of the class might think #subtractOne works, and then end up with unexpected values. It can be more serious in a real application - recently, I've been upgrading a VisualWorks 7.6 application to VisualWorks 7.9.1. One of the parts swallowed exceptions like what we have above, and finding the missing methods became very difficult.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Tags: ,

[st4u324-iPhone.m4v ( Size: 3647888 )]

posted by James Robertson

 Share Tweet This