<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/10/2e396edc1a3284cc4f0f4aa31e4c10b2"
  from="Basile Starynkevitch &lt;basile.starynkevitch@i...&gt;"
  author="Basile Starynkevitch"
  date="2003-10-08T18:44:11"
  subject="Re: [Caml-list] line numbers in exceptions"
  prev="2003/10/7778131e9bb9dc8f0e37e810e13cd361"
  next="2003/10/bfa15ffef4ce902d4ae1ce0139df5072"
  prev-in-thread="2003/10/d04befa7beb24ef22b9d02a9066de8f7"
  prev-thread="2003/10/8e30e035c3408ed133428b3777754c4d"
  next-thread="2003/10/23020cf3ef994a55faf67bc004acf3fd"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] line numbers in exceptions">
<msg 
  url="2003/10/d04befa7beb24ef22b9d02a9066de8f7"
  from="Lex Stein &lt;stein@e...&gt;"
  author="Lex Stein"
  date="2003-10-08T18:04:37"
  subject="[Caml-list] line numbers in exceptions">
<msg 
  url="2003/10/2e396edc1a3284cc4f0f4aa31e4c10b2"
  from="Basile Starynkevitch &lt;basile.starynkevitch@i...&gt;"
  author="Basile Starynkevitch"
  date="2003-10-08T18:44:11"
  subject="Re: [Caml-list] line numbers in exceptions">
</msg>
</msg>
</thread>

<contents>
On Wed, Oct 08, 2003 at 02:04:33PM -0400, Lex Stein wrote:
&gt; Hi, Is there a general strategy for getting the line number information
&gt; into exceptions. [...] Is there something like cpp's
&gt; __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 &amp; 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 (&amp; 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

</contents>

</message>

