From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 6E5D7BB81 for ; Sat, 11 Mar 2006 14:27:52 +0100 (CET) Received: from gw-eur4.philips.com (gw-eur4.philips.com [161.85.125.10]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k2BDRp5B013727 for ; Sat, 11 Mar 2006 14:27:51 +0100 Received: from smtpscan-eur5.philips.com (smtpscan-eur5.mail.philips.com [130.144.57.168]) by gw-eur4.philips.com (Postfix) with ESMTP id DFE7049709; Sat, 11 Mar 2006 13:27:50 +0000 (UTC) Received: from smtpscan-eur5.philips.com (localhost [127.0.0.1]) by localhost.philips.com (Postfix) with ESMTP id AD5443B; Sat, 11 Mar 2006 13:27:50 +0000 (GMT) Received: from smtprelay-eur2.philips.com (smtprelay-eur2.philips.com [130.144.57.171]) by smtpscan-eur5.philips.com (Postfix) with ESMTP id 9024E3A; Sat, 11 Mar 2006 13:27:50 +0000 (GMT) Received: from ehvrmh02.diamond.philips.com (ehvrmh02-srv.diamond.philips.com [130.139.27.125]) by smtprelay-eur2.philips.com (Postfix) with ESMTP id 6C47B33; Sat, 11 Mar 2006 13:27:50 +0000 (GMT) In-Reply-To: <20060306111412.GA12323@furbychan.cocan.org> To: Richard Jones Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Line number for index out of bounds / Exceptions for left hand side of assignments MIME-Version: 1.0 X-Mailer: Lotus Notes Release 6.0.3 September 26, 2003 From: Andries Hekstra Message-ID: Date: Sat, 11 Mar 2006 14:26:34 +0100 X-MIMETrack: Serialize by Router on ehvrmh02/H/SERVER/PHILIPS(Release 6.5.3FP1HF291 | September 19, 2005) at 11/03/2006 14:26:38, Serialize complete at 11/03/2006 14:26:38 Content-Type: multipart/alternative; boundary="=_alternative 0048FF47C125712E_=" X-Miltered: at concorde with ID 4412D057.003 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; workarounds:01 assertion:01 ocaml:01 syntax:01 eindhoven:01 ocaml:01 stack:01 workarounds:01 bytecode:01 stack:01 assertion:01 ocamlopt:01 notepad:01 syntax:01 eindhoven:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=HTML_40_50,HTML_MESSAGE autolearn=disabled version=3.0.3 This is a multipart message in MIME format. --=_alternative 0048FF47C125712E_= Content-Type: text/plain; charset="US-ASCII" 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 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 --=_alternative 0048FF47C125712E_= Content-Type: text/html; charset="US-ASCII"
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

--=_alternative 0048FF47C125712E_=--