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
Catching exceptions from OCaml callbacks
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Cannasse <warplayer@f...>
Subject: Re: "ocaml_beginners"::[] Catching exceptions from OCaml callbacks
> I may be missing something here but in Ch 18 of the manual, is there
> anything which describes how to catch the case when a OCaml callback
> throws an exception.
> eg:
> value foo = callback (*caml_named_value ("my function"), arg);
> and the registered function throws an exception instead of returning
> in the normal way; is there some way to test for this?

you have to call callback_exn instead of callback and then test for
Is_exception_result(foo) and if true you can get the raised exception with
Extract_exception(foo). All of theses are defined in lib/caml/callback.h

Nicolas Cannasse