[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Throwing an Unix.unix_error from C code



On Mon, 2007-03-26 at 17:48 +0200, Goswin von Brederlow wrote:
> > exception Unix_error of error * string * string
> So what structure do I need to throw?
You need to create a 4-tuple:

exn = caml_alloc(4,0);
Store_field(exn,0, *caml_named_value("Unix.Unix_error"));
Store_field(exn,1, <ML int of corresponding Unix.error tag>);
Store_field(exn,2, caml_copy_string(sterror(errno))); // or whatever
Store_field(exn,3, caml_copy_string("myfunc:")); // or whatever
caml_raise(exn);

> Or can caml_raise_with_arg only throw exceptions with a single
> argument?
Right, it's just a convience function (like caml_raise_constant).




Reply to: