From: "Sébastien Hinderer" <Sebastien.Hinderer@ens-lyon.org>
To: caml-list@inria.fr
Subject: Raising an exception with several arguments from C
Date: Sun, 3 Apr 2005 11:46:20 +0200 [thread overview]
Message-ID: <20050403094620.GA2436@galois> (raw)
Dear all,
In chapter 18 of Ocaml's manual, two functions are mentionned to
raise exceptions from C: caml_raise_constant which raises a
constant exception, and caml_raise_with_arg which raises an exception
with one argument.
However, assume the following declaration:
exception E of int * string;;
Then E is actually an exception with _two_ arguments, and not an
exception with one pair argument. Consequently, caml_raise_with_arg can
not be used to raise E from within a C function.
There are two solutions to this problem:
(1) declare E as follows :
exception E of (int * string)
Then E will be an exception with one argument (which is a pair), so it
will be possible to raise E thanks to caml_raise_with_arg.
(2) As can be seen in the sources of the Unix module, an exception with
n arguments (n>=2) is stored as a block of size n+1 tagged with 0. The
field 0 of this block contains the value describing the exception, as
returned by the caml_named_value function. Fields 1 to n contain values
corresponding to arguments 1 to n of E (this encoding comes from the
fact that exceptions are variants, I guess?).
Once this block (let's call it res) is allocated and properlz filled,
E can be raised thanks to a call such as
caml_raise(res);
(caml_raise is declared in caml/fail.h).
Unfortunately, caml_raise does not seem to be documented in Caml's
manual. Moreover, as far as I know, nothing is said about raising
exceptions with more than one argument.
Perhaps this point could be clarified in future versions of the manual ?
Cheers,
Sébastien.
reply other threads:[~2005-04-03 9:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050403094620.GA2436@galois \
--to=sebastien.hinderer@ens-lyon.org \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).