From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA06750; Wed, 12 Jun 2002 17:27:31 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA06637 for caml-list@pauillac.inria.fr; Wed, 12 Jun 2002 17:27:30 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA30968; Wed, 12 Jun 2002 10:53:08 +0200 (MET DST) Date: Wed, 12 Jun 2002 10:53:08 +0200 From: Xavier Leroy To: Michael Vanier Cc: gaurav_chanda@lycos.com, caml-list@pauillac.inria.fr Subject: Re: [Caml-list] Catching exceptions into strings Message-ID: <20020612105308.B29875@pauillac.inria.fr> References: <200206102157.g5ALvZg04810@orchestra.cs.caltech.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <200206102157.g5ALvZg04810@orchestra.cs.caltech.edu>; from mvanier@cs.caltech.edu on Mon, Jun 10, 2002 at 02:57:35PM -0700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Hmm. I didn't think it was possible to catch floating point exceptions in > ocaml (something I'd very much like to be able to do). Why doesn't ocaml > support this? Or does it? Your question requires a bit of decoding. Floating-point operations in OCaml follow the IEEE-standard usage of never causing an exception, but return infinities or (silent) NaNs when something is weird. The "Floating point exception" you saw in Gaurav's message is a misnomer: *integer* division by zero generates a SIGFPE signal under Unix, which is printed as "Floating-point exception" but really means "Integer arithmetic exception". Most processors (and I believe the IEEE standard) offer the option to raise exceptions instead of returning NaNs, infinities or denormals. This facility is not available from OCaml because it's not provided by ANSI C nor by POSIX, which are essentially what the OCaml runtime system is building upon. Even then, you'd get a SIGFPE when a floating point operation goes bad, and we're back to the issue of mapping a Unix *synchronous* signal to a Caml exception. (Asynchronous signals are already dealt with.) It can be done, although not trivially. But the main issue here is to get enough context about the signal. Raising Division_by_zero every time SIGFPE is received is not correct: maybe someone did "kill -FPE " from the outside; maybe the SIGFPE was generated inside a C library linked with the Caml code, and which has its own rules for dealing with it. In other terms, what is needed is to collect enough context on the SIGFPE occurrence to 1) make sure it's an integer division operation that failed, and 2) make sure this happened in OCaml code; only then we could generate a Division_by_zero exception. But of course there is no portable way to do all this under Unix. In summary: you can get SIGFPE, but they can only stop your program, handling them as exceptions is just not possible. - Xavier Leroy ------------------- 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