From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA18728; Wed, 8 Oct 2003 20:44:11 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA24006 for ; Wed, 8 Oct 2003 20:44:10 +0200 (MET DST) Received: from bourg.inria.fr (bourg.inria.fr [128.93.11.100]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h98IiA109869 for ; Wed, 8 Oct 2003 20:44:10 +0200 (MET DST) Received: from starynke by bourg.inria.fr with local (Exim 4.24) id 1A7JI9-0006s9-Rv; Wed, 08 Oct 2003 20:44:09 +0200 Date: Wed, 8 Oct 2003 20:44:09 +0200 To: Lex Stein , caml-list@inria.fr Subject: Re: [Caml-list] line numbers in exceptions Message-ID: <20031008184409.GA26380@bourg.inria.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.4i From: Basile Starynkevitch X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 basile:01 basile:01 0400,:01 stein:01 camlp:01 luggage:99 sourceforge:01 poesia:01 poesiasoft:01 cristal:01 cristal:01 ocaml:01 int:01 preprocessor:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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