List of Phobos functions that allocate memory?

Jakob Ovrum jakobovrum at gmail.com
Sat Feb 8 10:26:08 PST 2014


On Saturday, 8 February 2014 at 16:50:53 UTC, Andrei Alexandrescu 
wrote:
> On 2/8/14, 3:02 AM, Jakob Ovrum wrote:
>> On Saturday, 8 February 2014 at 00:49:46 UTC, Andrei 
>> Alexandrescu wrote:
>>> One simple idea is to statically allocate the same exception 
>>> and
>>> rethrow it over and over. After all there's no guarantee a 
>>> distinct
>>> exception is thrown every time, and the approach is still 
>>> memory safe
>>> (though it might surprise the programmer who saves a 
>>> reference to an
>>> old exception).
>>>
>>> Andrei
>>
>> I don't think it's that simple. What happens if an XException 
>> causes
>> another XException and they need to be chained together?
>
> The chaining method detects that and .dup's one of them.
>
> Andrei

What if the statically allocated XException is escaped to be 
inspected later, but before that is thrown again in a separate 
exception chain?

I suppose it would be no different from the current situation, as 
it's legal to throw exceptions allocated in any fashion, so there 
is already no guarantee of uniqueness. It's probable that some 
code out there still takes exception uniqueness for granted, so 
changing the allocation scheme would be a (typically silent) 
breaking change, even if the code is arguably broken in the first 
place. I suppose we could make that breakage a compile error by 
making exceptions implicitly `scope` at the catch-site, but that 
would of course be a much more involved change...

Personally I still like the idea, but if implemented, I think 
something should be done about the change in uniqueness at the 
same time, even if it's just an added note in the language 
documentation on exceptions.


More information about the Digitalmars-d mailing list