The Right Approach to Exceptions

Jonathan M Davis jmdavisProg at
Sat Feb 18 17:13:02 PST 2012

On Saturday, February 18, 2012 19:01:31 Robert Jacques wrote:
> That an argument of an internationalization module as part of the standard
> library, not for or against a particular exception module. I don't know
> what a good/robust module would look like, but many open source projects
> simply use a global string[string] and it seems to work okay for them.

It's an argument against making it so that the only way to get the error 
information from an exception is toString.

Exception handling is far more flexible when the exception's type and member 
variables gives you the information you need to actually handle the exception 
- or in the case of internationalization, generate your own error message. But 
ideally, users wouldn't see the result of an exception's toString regardless 
(especially since that includes stuff like the stack trace). Not even the msg 
field is really acceptable for that IMHO. It's great for debugging and maybe 
log messages, but not dealing with the user. To deal with the user 
appropriately, you need to know _what_ went wrong in a way that your program 
can process it and react appropriately, which strings just don't do.

- Jonathan M Davis

More information about the Digitalmars-d mailing list