C++/D interface: exceptions

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 12 13:30:56 PDT 2014


On 12 Sep 2014 19:00, "via Digitalmars-d" <digitalmars-d at puremagic.com>
wrote:
>
> On Friday, 12 September 2014 at 16:37:43 UTC, H. S. Teoh via
Digitalmars-d wrote:
>>
>> On Fri, Sep 12, 2014 at 06:19:54PM +0200, Marco Leise via Digitalmars-d
wrote:
>>>
>>> Am Fri, 12 Sep 2014 15:55:37 +0000
>>> schrieb "Sean Kelly" <sean at invisibleduck.org>:
>>>
>>> > On Friday, 12 September 2014 at 06:56:29 UTC, Jacob Carlborg > wrote:
>>> > > On 64bit Objective-C can catch C++ exceptions. But I don't > >
think you can do anything with the exception, i.e. it uses > > the
following catch syntax:
>>> > >
>>> > > @catch(...) {}
>>> > >
>>> > > Would that be easier?
>>> > > I think the trick is setting up the stack frame in such a > way
that the C++ exception mechanism knows there's a catch > block available at
all.  From there, we should be able to > use the standard
interface-to-class method to call virtual > functions on the exception
object, and hopefully the C++ > runtime will handle cleanup for us.
>>>
>>> What exception object?
>>>
>>> throw "bad things happened";
>>
>> [...]
>>
>>
>> Yeah, in C++, you can throw *anything*. Including ridiculous things like
>> `throw NULL;` or `throw 3.14159;`. There's no method for that! What we
>> might end up doing, might be to wrap the C++ exception in a D exception
>> that contains a pointer to the C++ type along with whatever type info we
>> can glean from the C++ runtime. We probably won't be able to do much
>> more than that.
>
>
> How about
>
>     try {
>         my_cpp_func();
>     } catch(CppException!(const(char)*) e) {
>         writeln(e.payload.fromStringz());
>     }
>
> ?
>

I'd vote no.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140912/84de5d81/attachment.html>


More information about the Digitalmars-d mailing list