Better diagnostics for null classes dereferencing

Neia Neutuladh neia at ikeran.org
Wed Jul 11 02:02:59 UTC 2018


On Tuesday, 10 July 2018 at 22:53:25 UTC, kdevel wrote:
>    extern (C) __gshared bool rt_trapExceptions;
>    static this ()
>    {
>       rt_trapExceptions = false;
>    }

This will catch exceptions raised in main and in static 
constructors that run after this one. However, if you put that 
code in the module that includes main(), it's probably going to 
be the last static constructor run. That means it doesn't impact 
other static constructors.

The only fix for that is putting this code in its own module that 
you add as the first import in every module. And if you depend on 
any library with a static constructor anywhere inside, you have 
to modify that library.

But exceptions can be thrown before any static constructor is 
run. The function that calls static constructors might detect a 
cycle straight off, for instance.

That's why the This Week In D post injected it into the C main 
function.


More information about the Digitalmars-d-learn mailing list