From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA00228 for caml-redistribution; Fri, 9 Jul 1999 01:44:50 +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 FAA26437 for ; Thu, 8 Jul 1999 05:56:33 +0200 (MET DST) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id FAA13876 for ; Thu, 8 Jul 1999 05:56:32 +0200 (MET DST) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id FAA25142; Thu, 8 Jul 1999 05:56:21 +0200 (MET DST) From: Markus Mottl Message-Id: <199907080356.FAA25142@miss.wu-wien.ac.at> Subject: Re: small code problem To: knotwell@f5.com Date: Thu, 8 Jul 1999 05:56:21 +0100 (MET DST) Cc: caml-list@inria.fr (OCAML) In-Reply-To: <14205.15754.427409.474325@knotwell.f5.com> from "Pierre.Weis@inria.fr" at Jul 2, 99 03:30:34 pm X-Mailer: ELM [version 2.4 PL21] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: weis > I'm having a problem with a core dump due to an uncaught exception. > The following snippet of code best illustrates the problem: [snip] > Why do the two compilers exhibit different behaviors with the same code? I'd say that this is an incompatibility bug between the byte- and native code compiler: Both actually throw an exception - it's just not the same! You didn't write which version of OCaml you use. The version I use (ocaml-2.02-2) does not produce a native code executable that crashes. It emits an uncaught exception to stderr instead. Try this very short file: let main () = Sys.argv.(1) let _ = Printexc.catch main () This should guarantee that any uncaught exceptions get printed to stderr instead of producing a core dump. Then you will see that this file compiled to byte code (ocamlc) produces this output: Uncaught exception: Invalid_argument("Array.get") Whereas the native code version (ocamlopt) produces: Uncaught exception: Invalid_argument("out-of-bound array or string access") The interpreter would behave like the byte code version - if we didn't have the second incompatibility that the argument vector behaves differently as mentioned in another current thread in the mailing list. Interesting that so far noone else has come across the incompatibility of exceptions in this case... > As an aside, I don't particular like my use of lazy and force. Is > there a cleaner way do the same thing? Yes, you only need to make "usage" a unit-function: let usage () = Printf.printf "Usage: %s file\n" Sys.argv.(0); exit ~-1 let filename = try Sys.argv.(1) with Invalid_argument("Array.get") -> usage () Best regards, Markus Mottl -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl