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 KAA28378; Wed, 12 Jun 2002 10:08:01 +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 KAA28354 for caml-list@pauillac.inria.fr; Wed, 12 Jun 2002 10:08:00 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA20156; Mon, 10 Jun 2002 17:07:43 +0200 (MET DST) Date: Mon, 10 Jun 2002 17:07:43 +0200 From: Xavier Leroy To: Gaurav Chanda Cc: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] Catching exceptions into strings Message-ID: <20020610170743.A19991@pauillac.inria.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: ; from gaurav_chanda@lycos.com on Mon, Jun 10, 2002 at 07:27:15AM -0700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I want to catch exceptions into strings. I do not want to have > pre-defined exceptions in my module which can be handled. I want to > catch exceptions like "floating point exceptions" etc. > > I wrote the follwing piece of code: > > value divide2 p = 2/p ; > > value foo p = > try divide2 p > with > [e -> let _ = do {print_string (Printexc.to_string e);flush stdout} in 9]; > > value _ = foo 0; > > (This code is in the Camlp4 revised syntax). > > When I compile and run this code, I get : > > Floating point exception > > However, after loading OCAML, if I use this file, I get > > value divide2 : int -> int = > value arbit : int -> int = > Division_by_zero > > That is, in the latter case, I get what I want but in the former > case, I don't. ocamlopt-generated code does not turn division by zero into an exception, like ocamlc-generated code or the toplevel environment do. Instead, you just get a hardware signal that kills the ocamlopt-generated program. See section 11.4 of the OCaml manual for a complete list of differences between ocamlopt and ocamlc. - 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