caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] line numbers in exceptions
@ 2003-10-08 18:04 Lex Stein
  2003-10-08 18:44 ` Basile Starynkevitch
  0 siblings, 1 reply; 2+ messages in thread
From: Lex Stein @ 2003-10-08 18:04 UTC (permalink / raw)
  To: caml-list


Hi, Is there a general strategy for getting the line number information
into exceptions. An exception call stack dump doesn't always work (for
example, with ocamlc -custom or ocamlopt). To figure out where my
exception is being raised, I'd like to paramaterize the exception by the
int line number. I don't want to enter this by hand because the exception
will change lines as I edit the code. Is there something like cpp's
__LINE__ and __FILE__ macros in OCaml? Or is the best way to just pump the
code through cpp before compilation?

Thanks,
Lex

--
Lex Stein                     http://www.eecs.harvard.edu/~stein/
stein@eecs.harvard.edu        cell: 617-233-0246

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] line numbers in exceptions
  2003-10-08 18:04 [Caml-list] line numbers in exceptions Lex Stein
@ 2003-10-08 18:44 ` Basile Starynkevitch
  0 siblings, 0 replies; 2+ messages in thread
From: Basile Starynkevitch @ 2003-10-08 18:44 UTC (permalink / raw)
  To: Lex Stein, caml-list

On Wed, Oct 08, 2003 at 02:04:33PM -0400, Lex Stein wrote:
> Hi, Is there a general strategy for getting the line number information
> into exceptions. [...] Is there something like cpp's
> __LINE__ and __FILE__ macros in OCaml? 

For macros, use camlp4. Exceptions don't carry more luggage than what they
claim, so if you want your exception SomeFault to carry the line & file
information, you obviously need to explicit

   exception SomeFault of string * int (* filename linenumber *)

Then you want to have a macro which e.g. expands a single (your new) keyword
   raise_Fault 
into 
   raise SomeFault(__FILE__,__LINE__)

where of course __FILE__ is a string (you want your preprocessor to put the
filename here) and __LINE__ is a number (you want your preprocessor to put
the current line number here).

As an example of macros which magically expands into something containing
the current source filename and line (& column) number, you can look at the
trace macro in the file pa_trace.ml (see also README.trace) inside

http://cvs.sourceforge.net/viewcvs.py/poesia/PoesiaSoft/PoesiaMonIcap/ 

I hope this will help you. Feel free to ask for more details if so needed.


-- 
Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr
Project cristal.inria.fr - phone +33 1 3963 5197 - mobile 6 8501 2359
http://cristal.inria.fr/~starynke --- all opinions are only mine 

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2003-10-08 18:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-08 18:04 [Caml-list] line numbers in exceptions Lex Stein
2003-10-08 18:44 ` Basile Starynkevitch

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