druntime function to query whether any exception is "in flight"

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Oct 20 15:16:33 UTC 2020


On 10/20/20 10:56 AM, Johan wrote:
> Hi all,
> 
> Weka is using a modified druntime. One of the modifications is adding a 
> function that you can use to query whether an exception is "in flight"
> 
> ```
> /****************************************
>   * Returns true when an exception is "in flight", where "in flight"
>   * means that an exception has been thrown but has not been caught yet.
>   *
>   * Returns:
>   *      true when an exception is "in flight" or not.
>   */
> extern(C) bool _d_eh_isExceptionInFlight()
> ```
> 
> The function is not exposed to the outside world, but knowledgeable 
> coders can access it using an extern(C) forward declaration.
> 
> Is this generally useful functionality and shall I upstream this to 
> druntime? I have not looked at whether this is easy to implement for the 
> Windows exception handling.
> If not, then I will upstream it to LDC's druntime fork.
> 
> thanks,
>    Johan
> 

That's awesome, it does belong in druntime! One change please - can you 
have it return the current exception as a Throwable (and null if no 
exception in flight)?

C++ does something similar, with a few contortions because C++ code 
doesn't necessarily throw objects with a common ancestor: 
https://en.cppreference.com/w/cpp/error/current_exception


More information about the Digitalmars-d mailing list