D exceptions and calling c++ code
Michel Fortin
michel.fortin at michelf.ca
Sat Mar 30 07:24:08 PDT 2013
On 2013-03-30 05:06:31 +0000, "J" <noname at notavailable.notavailabe.com> said:
> Is there anything that would prevent D from catching C++ exceptions?
>
> It would be nice to be able to leverage C++ libraries, but if you can't
> catch C++ exceptions, I'm not sure how realistic that is.
>
> That doesn't mean that catch() in D has to be the catcher.
>
> If there was some way to indicate that a function call was into a C++
> library, and perhaps some way to auto-generate, at the call point, the
> boilerplate that does the "catch this C++ exception and re-throw it as
> a D exception" translation, that would be awesome.
>
> Possible?
In my D/Objective-C hack I made a few years ago, I made it work for
Objective-C exceptions [1]. So it's certainly doable.
[1]: http://michelf.ca/projects/d-objc/syntax/#exceptions
It would be more tricky though because C++ exceptions are thrown
by-value. And some things will have to work differently to accommodate
each platform's ABI. And you'll likely get a performance penalty in
normal code for settings the handler frames.
But it can be done.
--
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca/
More information about the Digitalmars-d
mailing list