Proposal: Exceptions and @nogc

Shachar Shemesh via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 6 06:00:44 PDT 2017


On 02/04/17 18:24, Dmitry Olshansky wrote:
> On 4/2/17 9:14 AM, Walter Bright wrote:
>> On 4/1/2017 11:50 PM, Nicholas Wilson wrote:
>>> On Sunday, 2 April 2017 at 05:16:23 UTC, Walter Bright wrote:
>>>> Problem
>>>> =======
>>>>
>>>> [...]
>>>
>>> How will this interact with preallocated exceptions (e.g.  from
>>> Liran's dconf
>>> talk last year)?
>>
>> It will copy them and throw the copy.
>
> Copy means allocate and then deallocate in the catch, defeating the
> whole propose of preallocating. Would it be possible to just set a bit
> somewhere that indicates that the exception is preallocated and need not
> be freed.
>
> So for instance:
>
> throw new Exception; // this is allocated exception
>
> auto e = makeMeAnException();
> throw e; // this is preallocated exception (need not be freed in the catch)
>
> ---
> Dmitry Olshansky

The preallocated exceptions in weka were created as a work around for 
exceptions requiring GC. If we can throw without invoking the GC, we'll 
probably be fine with tossing them.

Shachar


More information about the Digitalmars-d mailing list