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 0B507BB9A for ; Tue, 8 Nov 2005 03:13:58 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jA82DvwI025294 for ; Tue, 8 Nov 2005 03:13:57 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id DAA24034 for ; Tue, 8 Nov 2005 03:13:57 +0100 (MET) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jA82Dte8025285 for ; Tue, 8 Nov 2005 03:13:56 +0100 Received: from rosella (ppp7-104.lns1.syd7.internode.on.net [59.167.7.104]) by smtp1.adl2.internode.on.net (8.12.9/8.12.6) with ESMTP id jA82DrJH080014 for ; Tue, 8 Nov 2005 12:43:53 +1030 (CST) (envelope-from skaller@users.sourceforge.net) Subject: Seeking exception source From: skaller To: caml-list@inria.fr Content-Type: text/plain Date: Tue, 08 Nov 2005 13:13:53 +1100 Message-Id: <1131416033.23991.57.camel@rosella> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 437009E5.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 437009E3.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; failwith:01 exn:01 handler:01 recursive:01 symbolic:01 stack:01 backtrace:01 underflow:01 stack:01 ......:98 ......:98 ....:98 ...:98 ...:98 ....:98 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=none autolearn=disabled version=3.0.3 I am occasionally annoyed by Not_found propagating to my top level function .. meaning the error could be anywhere at all in my program. I usually do this rubbish to fix it: ...... e ...... (* where e might raise an exception *) ==> .... begin try e with Not_found -> failwith "Not_found at So and So" end ... and then litter the code with such things until I've found where the problem is. This is very bad. A better way? Something like this: let f x ... = .... ===> let f x ... = begin try ...... with (x:exn) -> wrap "in function f" x end where let wrap s x = raise (TaggedExn ( s,x)) The idea is that every exception continues to propagate as normal .. but it gets a tag of where it came from wrapped around it. The handler can then report it. This mechanism is no use in a recursive function, nor where some exception can legitimately escape .. however both these could be taken into account: the general idea is to add a symbolic stack backtrace to exceptions which represent errors that WILL propagate to the top level (ie. underflow the stack). Any ideas how to do that? Perhaps a camlp4 thing to instrument marked functions? Although it isn't clear catching exceptions costs anything if none are thrown (other than code bloat)? [Actually in C the macro __LINE__ solves this .. but caml doesn't have such macros ..] -- John Skaller Felix, successor to C++: http://felix.sf.net