The Right Approach to Exceptions

Andrei Alexandrescu SeeWebsiteForEmail at
Sun Feb 19 23:10:39 PST 2012

On 2/20/12 12:44 AM, foobar wrote:
> I just died a little reading this. Are you suggesting that in order
> to handle IO exceptions I need to: try { ...whatever... } catch
> (PackageException!"") {...} } catch
> (PackageException!"") {...} } catch
> (PackageException!"") {...} ...
> What the hell is wrong with just using an IOException?

There's nothing wrong, but there's a possible misunderstanding. If and cooperate with std, then they'd originate
exceptions in (as opposed to their own). Do note that the issue
is exactly the same if libraries use IOException - they all must agree
on using the same nomenclature, whether it's called
PackageException!"" or IOException.

ModuleException and PackageException have one important thing going for
them: they automate away a good amount of boilerplate, which makes them
interesting for me to look at, and worth sharing as long as we're
brainstorming. The associated issues as clear as the advantages.
Probably ModuleException is too specific to be interesting, but
PackageException seems useful.

> AS Nick wrote, it seems you have a complete lack of understanding of
>  how exceptions work which is unsurprising coming from a c++ expert.

Always eager to learn (so please come with all you've got), but quite
honest I hope in a way you're exaggerating, seeing as a lot of the stuff
I authored for D (the scope statement, exception chaining, a full
chapter in TDPL) would be completely broken.

> Also, this entire discussion you started about "improving" exceptions
> looks to me like a combination of NIH syndrome sparkled with heavy
> doses of premature optimization.

What is being optimized here?



More information about the Digitalmars-d mailing list