https://issues.dlang.org/show_bug.cgi?id=23973

          Issue ID: 23973
           Summary: static constructors should have to be nothrow
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: [email protected]
          Reporter: [email protected]

Since initialisation order is undefined, throwing in a static constructor can
end up not having a stack trace (the runtime isn't initialised yet), or
probably worse (the GC insn't initialised yet). Also, there's nothing a user
can actually do to recover since it happens before their program even
technically begins. Even logging the exception is a bad idea because, again,
initialisation (or the lack thereof).

I've been bitten by this and have made all my static constructors nothrow ever
since, and I don't think there's any utility in ones that do.

--

Reply via email to