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 DEFACBB81 for ; Mon, 6 Mar 2006 12:14:40 +0100 (CET) Received: from furbychan.cocan.org (furbychan.cocan.org [80.68.91.176]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k26BEZvo001848 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Mon, 6 Mar 2006 12:14:40 +0100 Received: from rich by furbychan.cocan.org with local (Exim 3.35 #1 (Debian)) id 1FGDfK-000487-00; Mon, 06 Mar 2006 11:14:14 +0000 Date: Mon, 6 Mar 2006 11:14:14 +0000 To: Andries Hekstra Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Line number for index out of bounds Message-ID: <20060306111412.GA12323@furbychan.cocan.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i From: Richard Jones X-Miltered: at concorde with ID 440C199B.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 stack:01 workarounds:01 bytecode:01 stack:01 assertion:01 ocamlopt:01 notepad:01 wrote:01 assert:01 assert:01 exception:01 exception:01 expression: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.0 required=5.0 tests=SPF_FAIL autolearn=disabled version=3.0.3 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