The Right Approach to Exceptions

foobar foo at
Mon Feb 20 12:01:27 PST 2012

On Monday, 20 February 2012 at 19:41:07 UTC, Nick Sabalausky 
> Ok, I just saw your explanation here:
> And, IIUC, I assume that inside "stringTemplate()", you'd then 
> access some
> table that roughly amounts to (yea, I know we don't have 2D 
> AAs):
> string[string, Locale] i18nTable;
> i18nTable["FileNotFoundExcepton", English] = "File ${filename} 
> not found";
> Then stringTemplate() would look that up, find the string "File 
> ${filename}
> not found" and essentially do:
> return "File ""filename")~" not found";
> Although obviously not hardcoded like that.
> Is that right?
> In that case, I like the general idea, *but* why not just use 
> reflection to
> access the members instead of essentially creating a JS-style 
> "class" with
> AAs? That way we don't have to either A. throw away the 
> benefits that class
> members have over AAs or B. violate DRY by duplicating field 
> members in an
> AA.

Seconded. Reflection seems a much better solution for this.
The i18n table would map (exception type) -> (language, format 
and the i18n formatter would use reflection to map field values 
to the format string.
a format string would be e.g. "File {filename} not found" and the 
formatter would replace {filename} with 

This does not require any modifications to the exception 

More information about the Digitalmars-d mailing list