The Right Approach to Exceptions
H. S. Teoh
hsteoh at quickfur.ath.cx
Mon Feb 20 12:25:06 PST 2012
On Mon, Feb 20, 2012 at 09:01:27PM +0100, foobar wrote:
> On Monday, 20 February 2012 at 19:41:07 UTC, Nick Sabalausky wrote:
[...]
> >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 string) 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
> e.class.getField("filename").
>
> This does not require any modifications to the exception mechanism.
Unfortunately, I don't think D supports runtime reflection yet. At
least, not to the point we need (accessing field values of a general
Object).
Although, as some have said, it's possible to work around this by using
.tupleof, which is still a better solution than Variant[string], because
at least you'd have compile-time type checking.
T
--
The peace of mind---from knowing that viruses which exploit Microsoft
system vulnerabilities cannot touch Linux---is priceless. -- Frustrated
system administrator.
More information about the Digitalmars-d
mailing list