The main reason I was looking for a higher level generic mechanism for catching C++ throws is the desparate lack of functional closures in C++. If there were such a thing, then it would easy to wrap all the lower level calls in a safe try-catch block which has the closure passed to it... Alas, I sat down and invented a poor-man's functional closure system for C++, along the lines of CAMLparam1, etc.... The world is welcome to this... (attached) It is intended for use in OCaml C++ interface stubs, hence the use of value parameters in the closure classes. An example of its use is here: // ----------------------------------------------------------- extern "C" void foreign_array_blit_ml_to_f(value varr1, value voff1, value varr2, value voff2, value vnel) { VClosure5(clos, varr1,voff1,varr2,voff2,vnel, { long off1 = Long_val(VClArg(voff1)); long nel = Long_val(VClArg(vnel)); foreign_array fsrc(FOREIGN_DOUBLE, 1, &nel, (void*)((double*)VClArg(varr1) + off1), foreign_array::STATIC); long off2 = Long_val(VClArg(voff2)); foreign_array *pdst = pdata(VClArg(varr2)); array_blit(&fsrc, 0, pdst, off2, nel); }, &varr1); safe_call(clos); } // ----------------------------------------------------------- - DM ----- 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 caml-list-request@inria.fr Archives: http://caml.inria.fr > Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >