Next / Previous / Contents / Shipman's homepage

5.24. ParseException

This is the exception thrown when the parse fails. These attributes are available on an instance:

.lineno

The line number where the parse failed, counting from 1.

.col

The column number where the parse failed, counting from 1.

.line

The text of the line in which the parse failed.

>>> fail = pp.NoMatch()
>>> try:
...     print fail.parseString('Is that an ocarina?')
... except pp.ParseException as x:
...     print "Line {e.lineno}, column {e.col}:\n'{e.line}'".format(e=x)
... 
Line 1, column 1:
'Is that an ocarina?'