Any libunwind experts n da house?

IgorStepanov via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 24 14:53:45 PDT 2014


On Wednesday, 24 September 2014 at 19:28:50 UTC, Andrei
Alexandrescu wrote:
> On 9/24/14, 9:54 AM, Iain Buclaw via Digitalmars-d wrote:
>> On 24 September 2014 16:07, Andrei Alexandrescu via 
>> Digitalmars-d
>> <digitalmars-d at puremagic.com> wrote:
>>> 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.
>
> Noice.
>
>> - 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.
>
> Yah. I'm thinking of simplifying assumptions, e.g. all C++ 
> exceptions map to one single D type called CppException, and we 
> can assume there's always a D handler on top of the stack. All 
> the CppException saves is a copy of the what() message from the 
> C++ exception.
>
>> 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. :)
>
> Well even a catch like that would definitely be an improvement.
>
>
> Andrei

I have one freaky example for you. This example can be
non-standart and danger but it works:
C++ side: http://pastebin.ru/PceYCOEq
special function catch exception, pass it to specified handler
and re-throw, if handler not found

D side: http://pastebin.ru/7FNBzXHw
D defines a special handler and pass it to catchException
result:
D code call C++ function

void throwEx(void *)
{
      throw 4;
}
and prints:
dside.CPPException!int.CPPException@(0): 4

Doesn't fire to me, please :)


More information about the Digitalmars-d mailing list