Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Basile Starynkevitch <basile.starynkevitch@inria.fr>
To: Lex Stein <stein@eecs.harvard.edu>, caml-list@inria.fr
Subject: Re: [Caml-list] line numbers in exceptions
Date: Wed, 8 Oct 2003 20:44:09 +0200	[thread overview]
Message-ID: <20031008184409.GA26380@bourg.inria.fr> (raw)
In-Reply-To: <Pine.BSF.4.51.0310081400380.3387@bowser.eecs.harvard.edu>

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


      reply	other threads:[~2003-10-08 18:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-08 18:04 Lex Stein
2003-10-08 18:44 ` Basile Starynkevitch [this message]

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=20031008184409.GA26380@bourg.inria.fr \
    --to=basile.starynkevitch@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=stein@eecs.harvard.edu \
    /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