www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - Customizing error behavior

reply =?UTF-8?Q?S=C3=B6nke_Ludwig?= <sludwig outerproduct.org> writes:
Is there any way to customize the behavior of the various `Error`s 
generated by Druntime? On Windows it's possible to redefine the error 
functions, such as onOutOfMemoryError or onRangeError, in your 
executable to let them override the ones defined in Druntime. However, 
on other systems that just leads to a duplicate symbol linker error.

The reason I'd like to modify the behavior is twofold:

- The output to `stderr` is lost in our setup (GUI application)
- The point of failure after an error was thrown inside of a fiber 
(vibe.d task) is not the place where it was raised, but the place where 
it was caught (at a subsequent `abort()` call)

If there is currently no way, could those symbols be changed to weak 
linkage to enable the Windows approach on other platforms?
Sep 12
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 13/09/2025 3:42 AM, Sönke Ludwig wrote:
 Is there any way to customize the behavior of the various `Error`s 
 generated by Druntime? On Windows it's possible to redefine the error 
 functions, such as onOutOfMemoryError or onRangeError, in your 
 executable to let them override the ones defined in Druntime. However, 
 on other systems that just leads to a duplicate symbol linker error.
 
 The reason I'd like to modify the behavior is twofold:
 
 - The output to `stderr` is lost in our setup (GUI application)
 - The point of failure after an error was thrown inside of a fiber 
 (vibe.d task) is not the place where it was raised, but the place where 
 it was caught (at a subsequent `abort()` call)
 
 If there is currently no way, could those symbols be changed to weak 
 linkage to enable the Windows approach on other platforms?
And below: https://github.com/dlang/dmd/blob/master/druntime/src/core/exception.d#L546
Sep 12
parent kinke <noone nowhere.com> writes:
On Friday, 12 September 2025 at 15:47:08 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 On 13/09/2025 3:42 AM, Sönke Ludwig wrote:
 If there is currently no way, could those symbols be changed 
 to weak linkage to enable the Windows approach on other 
 platforms?
Sure, there's a standardized `core.attribute.weak` UDA nowadays, so these functions could be annotated in upstream druntime, working with all compilers then (DMD emits all functions as weak on non-Windows, so the ` weak` there is just a dummy).
 https://github.com/dlang/dmd/blob/master/druntime/src/core/exception.d#L546
The mentioned functions don't go through the customizable `assertHandler`.
Sep 12