From: Andries Hekstra <andries.hekstra@philips.com>
To: Richard Jones <rich@annexia.org>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Line number for index out of bounds / Exceptions for left hand side of assignments
Date: Sat, 11 Mar 2006 14:26:34 +0100 [thread overview]
Message-ID: <OF5E86A07C.805248E9-ONC125712E.00488B5A-C125712E.0049F3DA@philips.com> (raw)
In-Reply-To: <20060306111412.GA12323@furbychan.cocan.org>
[-- Attachment #1: Type: text/plain, Size: 2704 bytes --]
Richard Jones wrote :
> Possible workarounds:
> ...
> * Surround every possible array index with a try ... with expression
> like this:
>
> try
> (* code which accesses the array *)
> with
> Invalid_argument "index out of bounds" -> assert false
>
> The "assert false" will print the line and character number of the
> assertion.
Dear Richard,
I agree with you that this is feasible whenever array elements feature in
the right hand side of assignments. But how about the left hand sides of
assignments ? E.g. the following obviously is not correct OCaml syntax.
let a = Array.init 2 0;;
try a.(2) <- 1
with
Invalid_argument "index out of bounds" -> assert false;;
let h = try a.(2)
with
Invalid_argument "index out of bounds" -> assert false in
h <- 1;;
Regards,
=Andries
------------------------------------------------------------------------
Dr. Ir. Andries P. Hekstra
Philips Research
High Tech Campus 27 (WL-1-4.15)
5656 AG Eindhoven
Tel./Fax/Secr. +31 40 27 42048/42566/44051
* Good open source break software for computer users :
http://www.workrave.org
Richard Jones <rich@annexia.org>
06-03-2006 12:14
To
Andries Hekstra/EHV/RESEARCH/PHILIPS@PHILIPS
cc
caml-list@yquem.inria.fr
Subject
Re: [Caml-list] Line number for index out of bounds
Classification
On Mon, Mar 06, 2006 at 11:44:31AM +0100, Andries Hekstra wrote:
> Invalid_argument("index out of bounds")
[...]
> Of course, I am very curious in which line number of the program this
> exception occurs.
> Is there any way to get hold of this line number?
This is a real problem with OCaml - it's impossible to get stack
traces of where an exception happens with native code. I'm assuming
you're using native code. I commonly have cases where a program dies
with "exception: Not_found" because I forgot to enclose some List.find
with an appropriate try ... with clause, or made some wrong
assumption. Tracking these down is time-consuming.
Possible workarounds:
* Use bytecode, and before running the program set the environment
variable OCAMLRUNPARAM=b which will print a stack trace.
* Surround every possible array index with a try ... with expression
like this:
try
(* code which accesses the array *)
with
Invalid_argument "index out of bounds" -> assert false
The "assert false" will print the line and character number of the
assertion.
* Hack ocamlopt to be able to print exceptions properly :-)
Rich.
--
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business -
http://team-notepad.com
[-- Attachment #2: Type: text/html, Size: 4830 bytes --]
next prev parent reply other threads:[~2006-03-11 13:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-06 10:44 Line number for index out of bounds Andries Hekstra
2006-03-06 11:14 ` [Caml-list] " Richard Jones
2006-03-06 14:39 ` Markus Mottl
2006-03-06 19:08 ` Andries Hekstra
2006-03-06 19:53 ` Richard Jones
2006-03-12 10:17 ` Martin Jambon
2006-03-12 11:02 ` Richard Jones
2006-03-11 13:26 ` Andries Hekstra [this message]
2006-03-07 15:55 ` Alan Falloon
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=OF5E86A07C.805248E9-ONC125712E.00488B5A-C125712E.0049F3DA@philips.com \
--to=andries.hekstra@philips.com \
--cc=caml-list@yquem.inria.fr \
--cc=rich@annexia.org \
/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;
as well as URLs for NNTP newsgroup(s).