[Dlang-study] [lifetime] Few root decisions to take on RC classes
destructionator at gmail.com
destructionator at gmail.com
Thu Nov 5 05:12:20 PST 2015
On Thu, Nov 05, 2015 at 11:19:11AM +0000, Marc Schütz wrote:
> Just Throwable being @rc isn't enough. Exceptions contain additional data,
> at the least a message, which is often dynamically generated.
That's a bad pattern we should discourage though. Generating a
string for an exception makes for less useful exceptions (extracting
data from them is harder) and is just generally wasteful because you
can avoid it.
Instead, we should be making exception subclasses that hold the data
you'd use to generate that string. Those would be user-defined and
managed however the data themselves would be... so the Exception
destructor is responsible for destroying them if structs or other
RC items, or leave them behind for the GC, or whatever.
The string member IMO ought to be outright deprecated and replaced
with a generator function, but that's not likely to happen... but
still if we need it, I'd say leave it as garbage collected and tell
the user it just isn't the best way to go.
More information about the Dlang-study
mailing list