caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Seeking exception source
@ 2005-11-08  2:13 skaller
  2005-11-08  2:57 ` [Caml-list] " Jon Harrop
  2005-11-08  9:06 ` Nicolas Cannasse
  0 siblings, 2 replies; 6+ messages in thread
From: skaller @ 2005-11-08  2:13 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-11-08 10:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-08  2:13 Seeking exception source skaller
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

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).