The Right Approach to Exceptions
Ben Davis
entheh at cantab.net
Sat Feb 18 17:10:10 PST 2012
On 18/02/2012 21:07, Andrej Mitrovic wrote:
> On 2/18/12, Nathan M. Swan<nathanmswan at gmail.com> wrote:
>> 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.
>
> It would be even nicer if we didn't need a mixin for classes that
> simply forward the ctor call to the base class ctor:
>
> class FileException : Exception { } // no-go, have to write a ctor
> that forwards to super
>
> AIUI this has something to do with ctors not being virtual. I think
> someone mentioned this could be improved one day.
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.
More information about the Digitalmars-d
mailing list