January 05, 2016
On 2016-01-05 21:07, Walter Bright wrote:

> How?

There's something called "__cxa_current_exception_type" [1], can that be of use?

[1] http://libcxxabi.llvm.org/spec.html

-- 
/Jacob Carlborg
January 05, 2016
On Tuesday, 5 January 2016 at 17:23:38 UTC, Walter Bright wrote:
> At the exit of a catch clause, the destructor on the caught C++ exception will be run, as would be expected by C++ programmers.

Does this work with rethrow? What if a D exception is thrown from a C++ catch block - will the C++ exception still be destroyed properly?

January 05, 2016
On Tuesday, 5 January 2016 at 21:30:21 UTC, Jakob Ovrum wrote:
> On Tuesday, 5 January 2016 at 17:23:38 UTC, Walter Bright wrote:
>> At the exit of a catch clause, the destructor on the caught C++ exception will be run, as would be expected by C++ programmers.
>
> Does this work with rethrow? What if a D exception is thrown from a C++ catch block - will the C++ exception still be destroyed properly?

To clarify, I mean a catch block in D code that catches as C++ exception.
January 05, 2016
On Tuesday, 5 January 2016 at 20:07:11 UTC, Walter Bright wrote:
> On 1/5/2016 10:51 AM, Elie Morisse wrote:
>> why not distinguish C++ exceptions from D ones in the personality routine?
>
> How?

Are you aware of https://syniurgeblog.wordpress.com/2015/11/20/calypso-catching-cpp-exceptions-in-d/?

For DMD if the personality functions sees the C++ exception class (3rd arg passed to the personality func) would it be hard to make it look for C++ catch clauses?

With Calypso those catch clauses are std::type_info pointers wrapped inside a D class so that cast() is used to differentiate D catch clauses from C++ ones in the action table, and the personality function match those std::type_info against the one from the C++ exception header by calling the virtual function type_info::__do_catch(type_info*).

A single personality routine handles both D and C++ exceptions, and I don't think having a different one for C++ exceptions would make things much easier. The tricky part for DMD is probably the std::type_info generation.
January 05, 2016
On 1/5/2016 1:22 PM, Jacob Carlborg wrote:
> On 2016-01-05 21:07, Walter Bright wrote:
>
>> How?
>
> There's something called "__cxa_current_exception_type" [1], can that be of use?
>
> [1] http://libcxxabi.llvm.org/spec.html
>

That only works with C++ types, not D types.
January 05, 2016
On 1/5/2016 2:58 PM, Elie Morisse wrote:
> On Tuesday, 5 January 2016 at 20:07:11 UTC, Walter Bright wrote:
>> On 1/5/2016 10:51 AM, Elie Morisse wrote:
>>> why not distinguish C++ exceptions from D ones in the personality routine?
>>
>> How?
>
> Are you aware of
> https://syniurgeblog.wordpress.com/2015/11/20/calypso-catching-cpp-exceptions-in-d/?

No, thanks for pointing it out. Your solution is clever. I'll have to think about which method is better.

Also,

    catch (C++)(ref exception e)

the (C++) seems redundant. The compiler can look at the type of e, and determine if it is C++ or not.

January 05, 2016
On 1/5/2016 1:30 PM, Jakob Ovrum wrote:
> On Tuesday, 5 January 2016 at 17:23:38 UTC, Walter Bright wrote:
>> At the exit of a catch clause, the destructor on the caught C++ exception will
>> be run, as would be expected by C++ programmers.
>
> Does this work with rethrow? What if a D exception is thrown from a C++ catch
> block - will the C++ exception still be destroyed properly?
>

My understanding is that rethrow invokes the copy constructor, so the original can still be destroyed.
January 06, 2016
On 01/05/2016 06:56 PM, Walter Bright wrote:
> On 1/5/2016 1:30 PM, Jakob Ovrum wrote:
>> On Tuesday, 5 January 2016 at 17:23:38 UTC, Walter Bright wrote:
>>> At the exit of a catch clause, the destructor on the caught C++
>>> exception will
>>> be run, as would be expected by C++ programmers.
>>
>> Does this work with rethrow? What if a D exception is thrown from a
>> C++ catch
>> block - will the C++ exception still be destroyed properly?
>>
>
> My understanding is that rethrow invokes the copy constructor, so the
> original can still be destroyed.

To clarify what C++ does, consider:

try { ... }
catch (std::exception& e)
{
   throw e;
}

This throws a copy of e and is almost always not the desired/expected behavior because the original dynamic type of e (which may be a class derived from std::exception) is lost. Now consider:

try { ... }
catch (std::exception& e)
{
   throw;
}

In this case no copy is created. The same exact dynamic object continues to be thrown up the chain.


Andrei
1 2
Next ›   Last »