The Right Approach to Exceptions

Jonathan M Davis jmdavisProg at
Tue Feb 21 23:33:13 PST 2012

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 

>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

More information about the Digitalmars-d mailing list