Module pyparsing :: Class ParseException
[hide private]
[frames] | no frames]

Class ParseException

source code

              object --+            
                       |            
exceptions.BaseException --+        
                           |        
        exceptions.Exception --+    
                               |    
              ParseBaseException --+
                                   |
                                  ParseException


Exception thrown when parse expressions don't match class;
supported attributes by name are:
- lineno - returns the line number of the exception text
- col - returns the column number of the exception text
- line - returns the line containing the exception text

Example::

    try:
        Word(nums).setName("integer").parseString("ABC")
    except ParseException as pe:
        print(pe)
        print("column: {}".format(pe.col))

prints::

   Expected integer (at char 0), (line:1, col:1)
    column: 1

Instance Methods [hide private]

Inherited from ParseBaseException: __dir__, __getattr__, __init__, __repr__, __str__, markInputline

Inherited from exceptions.Exception: __new__

Inherited from exceptions.BaseException: __delattr__, __getattribute__, __getitem__, __getslice__, __reduce__, __setattr__, __setstate__, __unicode__

Inherited from object: __format__, __hash__, __reduce_ex__, __sizeof__, __subclasshook__

Class Methods [hide private]

Inherited from ParseBaseException (private): _from_exception

Static Methods [hide private]
 
explain(exc, depth=16)
Method to take an exception and translate the Python internal traceback into a list of the pyparsing expressions that caused the exception to be raised.
source code
Properties [hide private]

Inherited from exceptions.BaseException: args, message

Inherited from object: __class__

Method Details [hide private]

explain(exc, depth=16)
Static Method

source code 

Method to take an exception and translate the Python internal traceback into a list of the pyparsing expressions that caused the exception to be raised.

Parameters:

  • exc - exception raised during parsing (need not be a ParseException, in support of Python exceptions that might be raised in a parse action)
  • depth (default=16) - number of levels back in the stack trace to list expression and function names; if None, the full stack trace names will be listed; if 0, only the failing input line, marker, and exception string will be shown

Returns a multi-line string listing the ParserElements and/or function names in the exception's stack trace.

Note: the diagnostic output will include string representations of the expressions that failed to parse. These representations will be more helpful if you use `setName` to give identifiable names to your expressions. Otherwise they will use the default string forms, which may be cryptic to read.

explain() is only supported under Python 3.