The Right Approach to Exceptions

H. S. Teoh hsteoh at
Sat Feb 18 17:20:41 PST 2012

On Sun, Feb 19, 2012 at 01:10:10AM +0000, Ben Davis wrote:
> I guess this is a bit off topic, but what you probably want is
> syntactic sugar that says "declare constructors matching all super
> constructors and calling through to them" and can be used in ANY class
> hierarchy (not necessarily exceptions). For example:
> class Subtype : Supertype {
>     super all;
> }
> If you want to expose just specific constructors, then there could
> also be a shorthand for "declare a constructor matching a specific
> super constructor and calling through to it" - so you don't have to
> repeat all the arguments. For example:
> class Subtype : Supertype {
>     super();
>     super(string,int);
> }
> That would then make it an entirely separate issue and completely
> not Exception-specific.


This is definitely something not specific to Exception. Quite often, you
want to create a derived class overriding just one or two members of the
base class, but end up having to copy-n-paste most of the many ctors in
the base class along with their elaborate arguments just so you can pass
through the arguments to them.

Having a way of simply saying "the ctors in this class default to the
base class ctors" will solve this problem in a very nice and logical
way. (I.e., you're sortof "inheriting the base class ctors", although
not exactly, of course.)


Today's society is one of specialization: as you grow, you learn more
and more about less and less. Eventually, you know everything about

More information about the Digitalmars-d mailing list