The Right Approach to Exceptions

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Feb 20 08:45:58 PST 2012


On 2/20/12 10:37 AM, foobar wrote:
> On Monday, 20 February 2012 at 15:50:08 UTC, Andrei Alexandrescu wrote:
>> Actually that just shuffles the matter around. Any setup does demand
>> that some library (in this case most probably the standard library) will
>> be a dependency knot because it defines the hierarchy that others should
>> use.
>
> Not accurate. A 3rd party library that want to be compatible will no
> doubt depend on the standard library's _exception hierarchy_ but that
> does *not* mean it should depend on the parallel functionality in the
> standard library. Per our example with IO, if I use tango.io I certainly
> do not want my application code to include redundantly both std.io and
> tango.io. I wanted to use tango.io as an *alternative* to std.io.

This is a confusion. Using PackageException!"std.io" does not require 
importing std.io. Conversely, using std.IOException _does_ require 
importing std.exceptions or whatnot. So from a dependency management 
viewpoint, PackageException is superior to IOException.

The converse disadvantage is that typos won't be caught during 
compilation. For example, using PackageException!"sdt.io" will go 
through no problem, but of course won't be caught by people waiting for 
a PackageException!"std.io".


Andrei



More information about the Digitalmars-d mailing list