C++/D interface: exceptions

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 12 09:27:31 PDT 2014


Am Thu, 11 Sep 2014 17:35:25 -0700
schrieb Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>:

> Hello,
> 
> 
> We are racking our brains to figure out what to do about exceptions 
> thrown from C++ functions into D code that calls them.
> 
> A few levels of Nirvana would go like this:
> 
> 0. Undefined behavior - the only advantage to this is we're there 
> already with no work :o).
> 
> 1. C++ exceptions may be caught only by C++ code on the call stack; D 
> code does the stack unwinding appropriately (dtors, scope statements) 
> but can't catch stuff.
> 
> 2. D code can catch exceptions from C++ (e.g. via a CppException wrapper 
> class) and give some info on them, e.g. the what() string if any.
> 
> Making any progress on this is likely to be hard work, so any idea that 
> structures and simplifies the design space would be welcome.
> 
> 
> Andrei

I would say aim for 1. I wouldn't expect any less or any more.
Exception handling seems to have a platform wide standard on
major OSs that D should follow (e.g. libunwind helps with
this on GCC dominated systems), but dealing with C++'s "throw
anything" seems overkill to me for the next milestone in C++
interop. After all there could be exceptions using multiple
inheritance, templated objects or basic data types thrown from
the C++ side.

-- 
Marco



More information about the Digitalmars-d mailing list