The Right Approach to Exceptions

H. S. Teoh hsteoh at
Sat Feb 18 11:58:14 PST 2012

On Sat, Feb 18, 2012 at 08:18:53PM +0100, Nathan M. Swan wrote:
> On Saturday, 18 February 2012 at 18:52:05 UTC, Andrei Alexandrescu
> wrote:
> >There's a discussion that started in a pull request:
> >
> >
> >
> >Let's come up with a good doctrine for exception defining and
> >handling in Phobos. From experience I humbly submit that catching
> >by type is most of the time useless.
> 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.

I think deadalnix's approach is better. Exceptions should not be
categorized by module. What if the module depends on submodules? Then
catching only that module's exceptions will miss exceptions thrown from
submodules. No, exceptions need to be based on *semantics* rather than
modules, like CommandLineException, not GetOptException.

> 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.

+1. This I agree with.


Never step over a puddle, always step around it. Chances are that
whatever made it is still dripping.

More information about the Digitalmars-d mailing list