The Right Approach to Exceptions
Jonathan M Davis
jmdavisProg at gmx.com
Sat Feb 18 18:38:16 PST 2012
On Saturday, February 18, 2012 20:30:45 Andrei Alexandrescu wrote:
> On 2/18/12 6:40 PM, H. S. Teoh wrote:
> > One word: internationalization. Then toString() falls flat on its face.
>
> No. I happen to have some expertise in the area as I've participated to
> two large and heavily internationalized systems. i18n has everything to
> do with string tables and formatting templates and emphatically nothing
> to do with exception hierarchies. The only possible link is that
> exceptions should provide the necessary hooks.
They do in that if you want to print a message because of that exception, you
need to print something in the correct language, and that won't work with
toString unless the exception type has built-in internationalization of some
kind - regardless of what that internationalization mechanism might be.
Regardless, it's going to generally be better to generate an application-
specific error message than just print out whatever Exception outputs with
toString (internationalized or otherwise). And you can't do that if all you
have to work with is toString. To do that, you need actual data on what went
wrong, which requires additional member variables, which means using a specific
exception type.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list