The Right Approach to Exceptions

Jacob Carlborg doob at
Tue Feb 21 23:55:39 PST 2012

On 2012-02-22 08:33, Jonathan M Davis wrote:
> On Wednesday, February 22, 2012 08:22:21 Jacob Carlborg wrote:
>> Now I'm completely lost. According to what I've read this is thread this
>> is exactly what you want to do, put the formatting inside the exceptions.
> No. He wants to provide a way for an external function to generically generate
> strings according to the format that you want when you generate the string.
> So, some function would take a formatting string of some kind and then read
> the corresponding values form the Variant[string] in Exception and generate a
> string according to that format string. How exactly that works, I don't
> understand (something about a string template language), but that's the idea.
> So, while you could still use toString, there would be a way to generate
> strings formatted the way that _you_ want rather than how toString would do it
> - and to do it in a generic manner.
> As long as this doesn't mean using Variant[string] as the way to inject all of
> the extra data into exceptions and we still use an exception hierarchy with
> the appropriate data members in derived exceptions, then I don't really see
> that as a problem. The problem is if we then also get rid of the hierarchy
> and/or try and put all of the data is the Variant[string] and only in the
> Variant[string].

I agree.

>> From the sounds of it, we have _some_ agreement to have an exception hierarchy
> with data members in derived classes where appropriate but to add the
> Variant[string] bit to Exception to enable the passing of other data that you
> might want but is not in the exception type normally as well as enable the
> fancy string formatting stuff that Andrei wants. But this thread is so long and
> complicated that I think that many of us are just confused.
> - Jonathan M Davis

Ok, I see.

/Jacob Carlborg

More information about the Digitalmars-d mailing list