Catching C++ std::exception in D

David Nadlinger via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 12 13:17:36 PST 2015


On Thursday, 12 November 2015 at 06:50:31 UTC, Walter Bright 
wrote:
> The tricky part with the personality function will likely be 
> recognizing std::exception* exceptions. I wonder if forwarding 
> the call to __gxx_personality_v0 will work.

This should be rather simple; you know it is C++ because of the 
metadata, and if you have access to RTTI (can just be hacked 
together with pragma(mangle, …)), you just do the type comparison 
then.

What has me quite a bit more worried is the lifetime handling 
involved in the usual "throw std::exception subclass by value, 
catch base class by reference" idiom. If I remember correctly, 
both GCC and Clang handle this by injecting a runtime function 
call into the end of the catch blocks. Their implementation must 
also support keeping the value around for rethrowing. At this 
point, I'm not aware of any fundamental incompatibilities, but it 
will certainly add to the complexity of the solution.

  — David


More information about the Digitalmars-d mailing list