Previous Next Contents

2.3   Errors

If some kind of error happens while compiling a quotation, Camlp4 or Objective Caml display an error message, which shows the source position of the error. By default, the error message highlights the whole quotation, but a quotation expander can specify more precise ``locations'' while parsing and generating its returning string.

A ``location'' is a couple of integers: the first one is the position of the first character of the concerned text, the second one the position of the first character after the concerned text.

2.3.1   Exception raised in an expander

To raise an exception in an expander, it is possible to use the function ``Stdpp.raise_with_loc'' instead of ``raise'', this first function having a supplementary parameter which is the location of the error relative to the begin of the quotation.

2.3.2   Error while parsing the expander result (string expanders)

A problem can arise in string expanders (those returning strings). The resulting string may hold syntax errors. In this case, for there is no ``input location'' for the error, and it is not directly possible to see this error.

To solve this problem, a special option of Camlp4 can be used: ``-QD'' (see the manual page). It is also possible to set the variable ``Pcaml.quotation_dump_file'' (see section 6.3). The offending string is then written in a file (whose name is specified by this option or this variable) and the error message gives the location of the error in this file.

This problem cannot arise in syntax trees expanders, for there is no parsing following the expansion.

2.3.3   Typing error

It is possible to specify precise source locations to some parts (antiquotations) of the expander resulting string. For this, there are to ways depending on the expander kind:


Previous Next Contents