Throwable class design

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Jan 30 12:40:26 PST 2013


On Wed, Jan 30, 2013 at 09:03:31PM +0100, rumbu wrote:
> Ok, maybe my thoughts are polluted by some C# programming practices,
> but I learnt that exceptions are never intended for the end user
> (one of the reasons is that the exception mesages are in most cases
> displayed in english language). In Windows world, throwing an
> exception displays a message with a nice two buttons: Close and
> Debug. This will make the accountant using my software very eager to
> click on Debug :)

Maybe that is accepted convention in the Windows world, but I consider
exceptions as an excellent way of conveying what went wrong to the user.
Such as "could not calculate cell value, expecting number in cell A5 but
got 'adfsdfas' instead". Throwing an exception is the cleanest way to
abort potentially deeply-nested calculation code and give the user a
useful message in the meantime. I would hate to manually propagate such
user errors by hand, just because of the convention that exception
messages should never be seen by the user!

OTOH, I do understand that *some* exceptions aren't intended for user
consumption, such as internal errors in the program that are useful only
to the programmer. In such cases, I would use separate branches of the
exception class hierarchy, one for user-consumable exceptions, one for
exceptions that should only be logged and replaced with a generic
message (like "The application has encountered an internal problem,
please report the problem to technical support". Though honestly, I can
never stand these sorts of messages... but I do know some people prefer
that than to seeing raw exception messages).


> My way to deal now with *unattended* exceptions is to log them for
> further investigation, but I will never display a raw exception
> message, considering the fact that my LOB applications are in most
> cases multilanguage.

I guess it depends on the application, but you could always use
i18n-keyed string in your exception messages instead of plain English.
(Or use a gettext-like system where the English string is the key to the
translation files.) Then you can translate the message before displaying
it to the user.


T

-- 
"Real programmers can write assembly code in any language. :-)" -- Larry Wall


More information about the Digitalmars-d mailing list