English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] line numbers in exceptions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-10-08 (18:44)
From: Basile Starynkevitch <basile.starynkevitch@i...>
Subject: Re: [Caml-list] line numbers in exceptions
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 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


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