I can has @nogc and throw Exceptions?

Eugene Wissner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 13 09:27:59 PDT 2016


I'm writing currently a library, that is 100% @nogc but not 
nothrow, and I slowly begin to believe that I should publish it 
already, though it isn't ready yet. At least as example.
std.experimental.allocator doesn't work nicely with @nogc. for 
example dispose calls destroy, that isn't @nogc.
I wrote a primitive native allocator for linux and some help 
functions, that replaces phobos functions till they aren't 
@nogc-ready. For example for throwing the exceptions:

void raise(T : Throwable, A...)(Allocator allocator, auto ref A 
args)
{
	auto e = make!T(allocator, args);
	throw e;
}


and you can throw then with raise!Exception("bla-bla")


On Wednesday, 13 July 2016 at 16:13:21 UTC, Adam Sansier wrote:
> On Wednesday, 13 July 2016 at 11:39:11 UTC, Lodovico Giaretta 
> wrote:
>> On Wednesday, 13 July 2016 at 00:57:38 UTC, Adam Sansier wrote:
>>> [...]
>>
>> You shall use a static per-thread Region allocator[1] backed 
>> by Mallocator[2].
>> Then you just make[3] exceptions inside it and throw them.
>> So you can allocate and chain exceptions until you end the 
>> memory established on creation.
>> Whenever you don't need the exception chain anymore (i.e.: you 
>> catched them and program is back in "normal" mode, you just 
>> reset the region allocator, so you have all of your memory 
>> again, for the next exception chain).
>>
>> [1] 
>> https://dlang.org/phobos/std_experimental_allocator_building_blocks_region.html
>> [2] 
>> https://dlang.org/phobos/std_experimental_allocator_mallocator.html
>> [3] https://dlang.org/phobos/std_experimental_allocator.html
>
> Am I going to have to do all this myself or is it already done 
> for me somewhere?




More information about the Digitalmars-d-learn mailing list