RFC: Change what assert does on error
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Sun Jun 29 19:35:04 UTC 2025
On 30/06/2025 7:16 AM, Sönke Ludwig wrote:
> Am 29.06.2025 um 20:04 schrieb Richard (Rikki) Andrew Cattermole:
>> What a couple of us are suggesting is that we change the default
>> behaviour from ``throw AssertError``.
>> To: ``printBacktrace; exit(-1);``
>
>
> This will be a serious issue for GUI applications where stderr will
> typically just go to /dev/null and then the application just
> inexplicably exits (an issue that we currently already encounter on user
> installations and so far it has been impossible to track down the
> source). Instead of `exit(-1)`, a much better choice would be `abort()`,
> which would at least trigger a debugger or the system crash report handler.
For posix that would be ok.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/abort.html
The issue is Windows.
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/abort?view=msvc-170
"Products must start up promptly, continue to run and remain responsive
to user input. Products must shut down gracefully and not close
unexpectedly. The product must handle exceptions raised by any of the
managed or native system APIs and remain responsive to user input after
the exception is handled."
https://learn.microsoft.com/en-us/windows/apps/publish/store-policies#104-usability
Hmm ok, technically we have no ability to publish to Microsoft store,
regardless of what we do here joy.
Okay, abort instead of exit.
> Regarding the assertion error message and the backtrace, it would be
> nice if there was some kind of hook to customize where the output goes.
> Generally redirecting stderr would be a possible workaround, but that
> comes with its own issues, especially if there is other output involved.
There is a hook.
https://github.com/dlang/dmd/blob/master/druntime/src/core/exception.d#L531
Set the function and you can do whatever you want.
More information about the Digitalmars-d
mailing list