Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: knotwell@f5.com
Cc: caml-list@inria.fr (OCAML)
Subject: Re: small code problem
Date: Thu, 8 Jul 1999 05:56:21 +0100 (MET DST)	[thread overview]
Message-ID: <199907080356.FAA25142@miss.wu-wien.ac.at> (raw)
In-Reply-To: <14205.15754.427409.474325@knotwell.f5.com> from "Pierre.Weis@inria.fr" at Jul 2, 99 03:30:34 pm

> 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




  reply	other threads:[~1999-07-08 23:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-02 22:30 <Brad Knotwell
1999-07-08  4:56 ` Markus Mottl [this message]
1999-07-08 22:49 ` Gerd Stolpmann
1999-07-09  0:27   ` <Brad Knotwell
1999-07-09  1:37     ` Fabrice Le Fessant
1999-07-08 18:23 Damien Doligez
     [not found] <199907090927.KAA09195@toy.william.bogus>
1999-07-09 13:56 ` Gerd Stolpmann
1999-07-11 19:23   ` Markus Mottl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199907080356.FAA25142@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=caml-list@inria.fr \
    --cc=knotwell@f5.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox