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

Johan Engelen j at j.nl
Tue Oct 20 17:24:48 UTC 2020


On Tuesday, 20 October 2020 at 15:16:33 UTC, Andrei Alexandrescu 
wrote:
> On 10/20/20 10:56 AM, Johan wrote:
>> 
>> ```
>> /****************************************
>>   * 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()
>> ```
>
> 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

Actually, I made it quite intentionally _not_ return the 
exception, to prevent trickery by the (way too smart ;-)) Weka 
devs.
Note that C++'s current_exception returns the exception that has 
just been caught, whereas the _d_eh_isExceptionInFlight function 
is there to detect an exception before it was caught (returns 
false when in catch clause). It's been a while... I did implement 
something like getCurrentException, but didn't like it. Hope I 
can find it somewhere still.

I'll prepare something to submit to druntime soon.

cheers,
   Johan




More information about the Digitalmars-d mailing list