Any way to create derived classes from Exception with canned messages?
jfondren
julian.fondren at gmail.com
Sat Jul 31 11:12:17 UTC 2021
On Saturday, 31 July 2021 at 08:25:56 UTC, Jeremy T. Gibson wrote:
> Now, https://github.com/dlang/druntime/blob/master/src/object.d
> clearly expresses that the constructors of Exception are @nogc.
> Therein lies the problem: there is no way to use the ~
> concatenation operator in a @nogc function. At least at my
> current level of understanding of D (versus my background in C#
> where this is trivial), I can't think of any other way to pass
> a pure/nogc pair of strings that won't trip up the safety
> parameters.
>
> Just as a raw test case, I tried the following:
>
> https://run.dlang.io/is/VmCKwV
>
`annotation()` should also be nothrow as it's called by the
nothrow constructor.
Option #1: https://run.dlang.io/is/OBNfxq
use a limited @nogc string formatter from dub, with an instance
buffer.
Option #2: https://run.dlang.io/is/Osoiyd
for such a simple format, do it manually.
Option #3: NotYetImplemented()
require the caller to call a non- at nogc function which can build a
string and then throw/return a constructed exception.
More information about the Digitalmars-d-learn
mailing list