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
Message-Id: <99070901192505.28040@schneemann>
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 ----------------------------------------------------------------------------
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:23 MET