Calypso and the future of D
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jan 23 10:43:30 PST 2015
On 1/23/15 10:27 AM, Elie Morisse wrote:
> Exception catching is next after the first light of my Ogre3D demo,
> Clang will probably simplify handling of C++ exceptions a lot.
On that front, a coworker gave me a simple idea for integration.
1. All C++ non-polymorphic types thrown cannot be caught in D
2. We (or Calypso) define D class counterparts for polymorphic types
thrown from C++, notably std::exception and subtypes. N.B. those are D
classes, not D structs
3. D code can catch std::exception. The only caveat is that the caught
exception cannot survive the catch statement. Given that calling into
C++ is not the paramount of safety in the first place, I'd say that's a
reasonable compromise.
Example:
----
import core.stdcpp.vector;
import core.stdcpp.exception;
core.stdcpp.exception g;
void fun(core.stdcpp.vector!int v)
{
try
{
v.push_back(42);
}
catch (core.stdcpp.exception e) // fine, can catch
{
g = e; // ouch, will dangle
}
}
----
Thoughts?
Andrei
More information about the Digitalmars-d
mailing list