June 05, 2023 [Issue 23973] New: static constructors should have to be nothrow | ||||
---|---|---|---|---|
| ||||
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: nobody@puremagic.com Reporter: atila.neves@gmail.com 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. -- |
Copyright © 1999-2021 by the D Language Foundation