Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] C++ Throws
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-08-28 (00:09)
From: David McClain <dmcclain1@m...>
Subject: Re: [Caml-list] C++ Throws
Hi Brian,

Yes, that technique is the one that I said previously works just fine. I was
hoping for a higher level generic handler, instead of wrapping each
individual lib call with this try-catch block.

I have been doing C++ to OCaml for years now with no difficulty. The catch
here is that OCaml appears to be interposing between the established higher
level catch handlers and the source of the throw exceptions. It appears to
insist on not allowing any lower dynamic exceptions to propagate above its
interface with a C call.

David McClain
Senior Corporate Scientist
Avisere, Inc.

+1.520.390.7738 (USA)

----- Original Message ----- 
From: "Brian Hurt" <>
To: "David McClain" <>
Cc: <>
Sent: Friday, August 27, 2004 16:24
Subject: Re: [Caml-list] C++ Throws

> On Fri, 27 Aug 2004, David McClain wrote:
> > I now see that OCaml is not converting anything, per se... Apparently
> > when the throw handler detects an unhandled condition it decides to
> > call abort(), against which there is no defense.
> I don't know what precisely is going on here, but Ocaml interfaces to C,
> which doesn't know anything about exceptions.  You might try something
> like (sorry, I'm no C++ guru):
> extern "C" value foo(value c);
> value foo(value C) {
>     /* normal Ocaml wrapper code for C */
>     try {
>         /* exception throwing code for C++. */
>     }
>     with (Exception e) {
>         /* Translate the C++ exception to an Ocaml exception */
>     }
> }
> The big difference between a C++ function and C function is the name
> mangling.  I doubt Ocaml could find a C++ function for linking after it
> was name mangled.  So the extern "C" tells C++ to not namemangle the
> function name.
> There is no way I know of to determine what exceptions a function call
> might throw.
> > So there appears to be something relatively complex going on across the
> > foreign function interface with OCaml and C. This override is what
> > frustrates the attempts to create a generic C++ exception handler.
> I think you also have a C/C++ interface problem (and yes, Virginia, they
> do exist).
> -- 
> "Usenet is like a herd of performing elephants with diarrhea -- massive,
> difficult to redirect, awe-inspiring, entertaining, and a source of
> mind-boggling amounts of excrement when you least expect it."
>                                 - Gene Spafford
> Brian
> -------------------
> To unsubscribe, mail Archives:
> Bug reports: FAQ:
> Beginner's list:

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: