Any libunwind experts n da house?

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 24 09:54:16 PDT 2014


On 24 September 2014 16:07, Andrei Alexandrescu via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 9/24/14, 5:12 AM, Iain Buclaw via Digitalmars-d wrote:
>>
>> On 24 September 2014 12:27, IgorStepanov via Digitalmars-d
>> <digitalmars-d at puremagic.com> wrote:
>>>
>>> On Tuesday, 23 September 2014 at 17:37:42 UTC, Andrei Alexandrescu wrote:
>>>>
>>>>
>>>> We need a libunwind expert to figure out a good approach for handling
>>>> exceptions thrown by C++ code into D.
>>>>
>>>> Is anyone fluent with libunwind?
>>>>
>>>>
>>>> Andrei
>>>
>>>
>>>
>>> Is there plans to catching C++ exceptions in D?
>>
>>
>> I'd say no to such an idea.
>
>
> I understand the difficulty of it. However, we should look into it closely.
> Preventing D code from catching C++ exceptions forces one to implement the
> driver/event loop/etc in C++, which is quite unpleasant. It essentially
> takes C++ compatibility a few good notches down.
>
>>> What kind of C++ exceptions planned to catch in D?
>>
>>
>> None
>
>
> I wonder how difficult would be to create a wrapper class CppException for
> everything derived from C++ std::exception. It would not save the exact
> exception, but it would save its what() string and perhaps the
> typeid().name(). A translator would create CppException objects from
> std::exception objects and their derivatives.
>
> How hard would that be? Please advise.
>

Thinking about it:

- Identifying a C++ exception, simple.

- Identifying whether a D catch handler for a C++ exception object
matches, tricky - maybe.  ABI of structs being a potential maintenance
burden - though you'd hope that they only change ABI once every two
years or so. Second, determining that the C++ object being thrown and
catch handler we are examining match might be awkward from D.  That is
something that needs investigation.

However, for sure, the easiest thing that could be done *now* that
only needs a slight EH library tweak is using catch-all handlers to
recover from any language exception.

try {
  SomeCxxFuncThatMayThrow();
}
catch {
  // Recover, but without knowing what happened.
}

But I'd imagine you'd actually want information to come with your
caught exception, though. :)

Iain


More information about the Digitalmars-d mailing list