The Right Approach to Exceptions

Sean Kelly sean at invisibleduck.org
Mon Feb 20 13:04:45 PST 2012


On Feb 20, 2012, at 12:54 PM, Andrei Alexandrescu wrote:

> On 2/20/12 1:41 PM, Sean Kelly wrote:
>> Localized error messages are typically generated by a localization
>> team and placed in some sort of a lookup table, indexed by language
>> and error code.  Say the code is roughly like this:
>> 
>> displayLocalizedError(Exception e) { auto t =
>> loadTable(e.info["lang"]); // info["lang"] returns "ja" for japanese,
>> etc. string m = t.findMessage(typeid(e).toString);
>> writeln(buildLocalizedMessage(m, e.info)); }
> 
> I'd amend your example a bit as follows:
> 
> displayLocalizedError(Exception e) {
>    auto t = loadTable(g_lang); // g_lang contains "ja" for japanese, etc.
>    string m = t.findMessage(typeid(e).toString);
>    writeln(buildLocalizedMessage(m, e.info));
> }
> 
> I mean the exception has no notion of "lang"uage.

I wrote it that way because the systems I work on don't have a global concept of language.  It's request-specific.  I wasn't sure how to succinctly represent this in the code, so I just dumped the field in the lookup table.


More information about the Digitalmars-d mailing list