I can has @nogc and throw Exceptions?

Adam Sansier via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 12 17:57:38 PDT 2016


On Friday, 13 February 2015 at 21:08:58 UTC, Marc Schütz wrote:
> On Friday, 13 February 2015 at 19:09:43 UTC, Tobias Pankrath 
> wrote:
>> 1. Throw preallocated exceptions is the way to go
>
> ... and because noone has yet shown an explicit example:
>
>     void myThrowingNogcFunc() @nogc {
>         static const exc = new Exception("something went 
> wrong");
>         throw exc;
>     }
>
> As long as you don't need to pass a runtime argument to the 
> constructor, there's no need for emplace acrobatics.

Why not? If the argument is static? (A string literal, surely 
this shouldn't be a problem and usually what is used?)


void myThrowingNogcFunc(string s)() @nogc
{
         static const exc = new Exception(s);
         throw exc;
}


?

I too am looking for nogc exceptions.

How about simply setting aside a 100kb of memory as a pool for 
exceptions. Seems like a lot but still under 640kb, hell, even 
1MB would still be tiny.

After all, it's not like exceptions are common or happen in 
complex ways.

Does anyone have a proper solution to this problem? I'd like nogc 
exception handling with run-time generated args.






More information about the Digitalmars-d-learn mailing list