Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Gerd Stolpmann <Gerd.Stolpmann@darmstadt.netsurf.de>
To: knotwell@f5.com, caml-list@inria.fr
Subject: Re: small code problem
Date: Fri, 9 Jul 1999 00:49:19 +0200	[thread overview]
Message-ID: <99070901192505.28040@schneemann> (raw)
In-Reply-To: <14205.15754.427409.474325@knotwell.f5.com>

On Sat, 03 Jul 1999, Brad Knotwell wrote:
>On the other hand, when I compile with the optimizing compiler, I
>receive the following:
>
>	[knotwell@knotwell stock]$ ocamlopt junk.ml
>	[knotwell@knotwell stock]$ ./a.out
>	Segmentation fault (core dumped)
>        [knotwell@knotwell stock]$	

On an x86 architecture I get a different result:
Fatal error: uncaught exception Invalid_argument("out-of-bound array or string access")

This means that there are two problems:
- The segfault
- The different exceptions raised by the bytecode and the native compiler.

>As an aside, I don't particular like my use of lazy and force.  Is
>there a cleaner way do the same thing?

let usage() = Printf.printf "Usage: %s file\n" Sys.argv.(0); exit ~-1;;
let filename =
	match Sys.argv with
 		[| |]   -> failwith "You have a silly operating system"
	      | [| _ |] -> usage()
	      | _       -> Sys.argv.(1)

This solution avoids that Invalid_argument must be caught which is better
style. It is almost always a bad idea to trap Invalid_argument, 
Out_of_memory, Stack_overflow, and Division_by_zero, as these exceptions
are thought as last resort that indicates a bad system state that must
not happen but happened. It is better to design the program such that
it never runs into conditions that raise these exceptions, and if they
happen nevertheless, you missed something.

Gerd
--
----------------------------------------------------------------------------
Gerd Stolpmann      Telefon: +49 6151 997705 (privat)
Viktoriastr. 100             
64293 Darmstadt     EMail:   Gerd.Stolpmann@darmstadt.netsurf.de (privat)
Germany                     
----------------------------------------------------------------------------




  parent reply	other threads:[~1999-07-08 23:46 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
1999-07-08 22:49 ` Gerd Stolpmann [this message]
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=99070901192505.28040@schneemann \
    --to=gerd.stolpmann@darmstadt.netsurf.de \
    --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