Sub-classing exceptions
Shriramana Sharma via Digitalmars-d
digitalmars-d at puremagic.com
Fri Oct 16 19:35:57 PDT 2015
Jacob Carlborg wrote:
> On 2015-10-15 20:07, Shriramana Sharma wrote:
>
>> $ cat myexception.d
>> string ExceptionDeclaration(string newExceptionName, string
>> baseExceptionName = "Exception")
>> {
>> return "class " ~ newExceptionName ~ ": " ~ baseExceptionName ~ `{
>> this(string msg = "", string file = __FILE__, size_t line =
>> __LINE__)
>> { super(msg, file, line); }
>> }`;
>> }
>
> I think constructors should be inherited.
Yes the constructors are inherited, but the problem, as I illustrated, is
that the inherited constructor gets the __FILE__ and __LINE__ data for the
point of declaring the exception subclass, and not at the point of throwing
it.
> If you declare the subclass as usual you can have a template mixin that
> adds the constructor.
>
> class SubException : Exception
> {
> mixin ExceptionConstructors;
> }
Hmmm is that in any way advantageous to what I wrote about it? Is it just
that you can now add a doc-comment that DDoc can recognize?
--
Shriramana Sharma, Penguin #395953
More information about the Digitalmars-d
mailing list