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 RAA06748; Wed, 12 Jun 2002 17:27:58 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA06864 for caml-list@pauillac.inria.fr; Wed, 12 Jun 2002 17:27:57 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA31817 for ; Wed, 12 Jun 2002 11:36:58 +0200 (MET DST) Received: from obento.cs.caltech.edu (obento.cs.caltech.edu [131.215.44.101]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g5C9avj27400 for ; Wed, 12 Jun 2002 11:36:57 +0200 (MET DST) Received: from orchestra.cs.caltech.edu (orchestra.cs.caltech.edu [131.215.44.20]) by obento.cs.caltech.edu (Postfix) with ESMTP id DD1F13DDE; Wed, 12 Jun 2002 02:36:54 -0700 (PDT) Received: (from mvanier@localhost) by orchestra.cs.caltech.edu (8.11.6/8.9.3) id g5C9asB18950; Wed, 12 Jun 2002 02:36:54 -0700 Date: Wed, 12 Jun 2002 02:36:54 -0700 Message-Id: <200206120936.g5C9asB18950@orchestra.cs.caltech.edu> X-Authentication-Warning: orchestra.cs.caltech.edu: mvanier set sender to mvanier@cs.caltech.edu using -f From: Michael Vanier To: xavier.leroy@inria.fr Cc: gaurav_chanda@lycos.com, caml-list@pauillac.inria.fr In-reply-to: <20020612105308.B29875@pauillac.inria.fr> (message from Xavier Leroy on Wed, 12 Jun 2002 10:53:08 +0200) Subject: Re: [Caml-list] Catching exceptions into strings References: <200206102157.g5ALvZg04810@orchestra.cs.caltech.edu> <20020612105308.B29875@pauillac.inria.fr> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Xavier, Thanks for the clear explanation of a topic that always puzzled me. Personally, I could live with SIGFPE just aborting the program. I'm also curious: is it possible to catch floating point errors in ocaml's bytecode? Or is this, too, dependent on the ansi C/Posix standards? I tried this with java and was interested to find that integer division by zero is caught but floating point division by zero isn't. Given all this, I wonder how C# handles "checked arithmetic"? Are the rules different on Windows? Mike > Date: Wed, 12 Jun 2002 10:53:08 +0200 > From: Xavier Leroy > > > 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