caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: Andries Hekstra <andries.hekstra@philips.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Line number for index out of bounds
Date: Mon, 6 Mar 2006 11:14:14 +0000	[thread overview]
Message-ID: <20060306111412.GA12323@furbychan.cocan.org> (raw)
In-Reply-To: <OF69D879A9.96F51C70-ONC1257129.003A8688-C1257129.003B1EBA@philips.com>

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


  reply	other threads:[~2006-03-06 11:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-06 10:44 Andries Hekstra
2006-03-06 11:14 ` Richard Jones [this message]
2006-03-06 14:39   ` [Caml-list] " 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   ` [Caml-list] Line number for index out of bounds / Exceptions for left hand side of assignments Andries Hekstra
2006-03-07 15:55 ` [Caml-list] Line number for index out of bounds Alan Falloon
2006-03-06 13:11 Jonathan Harrop
2006-03-07  9:39 ` Nicolas Pouillard

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=20060306111412.GA12323@furbychan.cocan.org \
    --to=rich@annexia.org \
    --cc=andries.hekstra@philips.com \
    --cc=caml-list@yquem.inria.fr \
    /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).