std library hooks
Walter Bright
newshound2 at digitalmars.com
Sat Apr 14 21:03:44 PDT 2012
On 4/14/2012 4:41 PM, Manu wrote:
> On 14 April 2012 22:51, Walter Bright <newshound2 at digitalmars.com
> <mailto:newshound2 at digitalmars.com>> wrote:
>
> On 4/14/2012 3:49 AM, Manu wrote:
>
> I have a D DLL, loaded into a C app, if D throws, C doesn't seem to be
> able to
> catch it and it just crashes without any useful messages. Maybe I'm
> doing it wrong?
>
>
> C has no exception handlers in it. C knows nothing about exceptions.
>
> I recommend that all your APIs in a D DLL be wrapped in something that
> catches all exceptions, and then does something recognizable to the calling
> C code.
>
>
> I mean to say C++, are the exceptions compatible?
No. For one thing, C++ can throw any type (like an int). That isn't even
expressible in D.
> I don't think it's feasible
> for me to wrap the top level of every function implemented in D in a try/catch
> statement. I suppose I'll just have to make use of a 'weak assert' in our code,
> where it may be possible to continue. I suppose library asserts will make the
> assumption they can absolutely not continue, so as long as I can hook a message
> first, the proceeding crash is fine.
Anything you want to recover from, wrap in a try/catch. For ones you don't want
to recover from, just do the log/notification and exit.
More information about the Digitalmars-d
mailing list