caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: caml-list@inria.fr
Subject: Seeking exception source
Date: Tue, 08 Nov 2005 13:13:53 +1100	[thread overview]
Message-ID: <1131416033.23991.57.camel@rosella> (raw)

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 <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


             reply	other threads:[~2005-11-08  2:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-08  2:13 skaller [this message]
2005-11-08  2:57 ` [Caml-list] " Jon Harrop
2005-11-08  9:06 ` Nicolas Cannasse
2005-11-08 10:30   ` Alessandro Baretta
2005-11-08 10:06     ` Nicolas Cannasse
2005-11-08 10:34       ` skaller

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=1131416033.23991.57.camel@rosella \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@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).