Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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 (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 - phone +33 1 3963 5197 - mobile 6 8501 2359 --- all opinions are only mine 

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: