VA Smalltalk: How to display the “real” error message


This is mostly a note to myself, because I tend to get caught in the same trap over and over again when it comes to displaying an error message from an Exception. I remember using trial and error several times and miserably failing.

What’s the problem?

I catch an exception and want to display a message to the user of my application, like in

[ myBusinessObject calculateSomeVeryComplicatedStuff ]
on: ExError
do: [:ex|
Transcript show: ex messageText.
ex exitWith: nil].

The problem is that I often forget to use the message messageText and keep on getting results like “(ExError) An Error has occured” instead of “The amount must be positive”, which is what I passed to the error: method.

Now I only have to remember that I once wrote this blog post to remind myself of messageText😉.
Joachim: Never try description or accesing the arguments of a Signal or anything, just use messageText, it really is that easy!

[Update] It seems it’s not only me. There is something broken about the exceptions. messageText is fine for sends of self error:, but if there is a MessageNotUnderstood exception, the result of messageText is only ‘TheClass>>theMessageThatWasntUnderstood’ instead of ‘TheClass does not Understand theMessageThatWasntUnderstood’.

At least now I know there is reason to be confused…

 

One thought on “VA Smalltalk: How to display the “real” error message

Comments are closed.