The Right Approach to Exceptions

Jonathan M Davis jmdavisProg at
Sat Feb 18 15:06:03 PST 2012

On Saturday, February 18, 2012 20:18:53 Nathan M. Swan wrote:
> Here's a compromise I would suggest: we have the different
> exception types for different exceptional behaviors, but still
> they all descend from a common exception type that has a field
> with the module name; this way, the client can choose which way
> they want to go.

If someone just wants to handle generic exceptions, then they can catch 
Exception. That's no reason to not actually have a proper exception hierarchy 
that programmers can use if they want to. Module-specific works on some level 
precisely because modules generally encompass specific behaviors (e.g. file 
handling or string handling), but a really well-designed exception hierarchy 
would not be specifically tied to modules the way that we are now. Rather, we'd 
have exceptions specific to behaviors, and different modules would reuse 
exceptions from other modules where appropriate based on what they're doing.

> It would be nice if there was a mixin template that creates an
> exception class that acts like this; making similar exception
> classes is annoying.

I've considered creating one (it woud be quite easy), but the problem is that 
you don't end up with any ddoc documentation for them.

- Jonathan M Davis

More information about the Digitalmars-d mailing list