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] OCaml and 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-27 (21:26)
From: David McClain <David.McClain@A...>
Subject: [Caml-list] OCaml and C++ Throws
I'm looking for any information on how to catch C++ derived throws from 
OCaml. Currently, these uncaught exceptions appear to trigger a SIGABRT 
(#6) that the runtime kernel appears to catch just so that it can print 
a message before aborting the application.

I have tried numerous schemes to interpose some try-catch clauses in 
C++ between OCaml and the called C++ libraries. So far all attempts 
have failed. It appears that the try-catch mechanism is a "local" 
mechanism in the sense that if you try-catch around the direct library 
call down in C++ that works fine, but if you allow the exception to 
propagate upward through the original OCaml-C call then OCaml grabs 
control of these exceptions. Any higher up C++ try-catch clauses 
containing the OCaml code that calls into the C layer again are 
frustrated from ever seeing these thrown exceptions.

OCaml appears to be converting these uncaught exceptions into signals 
that the runtime handles on behalf of the application. Any attempt to 
intercept these SIGABRT signals with my own handlers using module Sys 
appear to be ignored.

Is there a way to generically handle C++ thrown exceptions? Having to 
know in advance which 3rd party libs will throw means also having to 
write explicit wrappers around each call to provide a catch clause for 
converting the messages into failwith() calls.

These experiments have so far been performed on Mac OS X 10.3.5 using 
the Mac variants of the GCC compiler with OCaml 3.07.

David McClain
Senior Corporate Scientist
Avisere, Inc.
+1.520.390.7738 (USA)

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