The D standard library is built on GC, is that a negative or positive?

Nick Treleaven nick at geany.org
Fri Dec 16 13:25:25 UTC 2022


On Friday, 16 December 2022 at 04:54:21 UTC, Siarhei Siamashka 
wrote:
> Another problem is illustrated by the example below:
>
> ```D
> T enforce(string msg, T)(T cond) {
>     if (!cond) {
>         static immutable e = new Exception(msg);
>         throw e;
>     }
>     return cond;
> }
>
> void main() {
>     try {
>         enforce!"trigger an exception"(1 == 2);
>     } catch (Exception e) {
>         assert(0, "if we reach here, then it's probably a 
> compiler bug");
>     } catch (immutable Exception e) {
>         // the proper place to handle it is here
>         assert(e.msg == "trigger an exception");
>     }
> }
> ```
>
> If it's an immutable exception, then the compiler should 
> probably only catch it as immutable?

This pull disallows throwing an immutable object:

https://github.com/dlang/dmd/pull/14706

You can still throw a const object though, which would work for 
your `enforce`.


More information about the Digitalmars-d mailing list