How do I catch ExpatError exception?
Mark Winrock
mwinrock at frontiernet.net
Wed Aug 16 20:06:45 EDT 2006
Shuaib wrote:
> Hey!
>
> I am getting this exception.
>
> xml.parsers.expat.ExpatError
>
> But I am not able to catch it with "except
> xml.parsers.expat.ExpatError:" It says "NameError: global name 'xml' is
> not defined".
>
> I am also not able to catch it with "except ExpatError:" Gives
> "NameError: global name 'xml' is not defined"
>
> How do I catch it? (I am parsing an xml file)
Have you imported xml.parsers.expat to get it properly scoped?
>
> Also, how do I get the line number where an exception was thrown?
>
Try looking at the 'sys.exc_info' and the 'traceback' module
documentation. Also see Python Cookbook recipe Recipe 8.6. Getting More
Information from Tracebacks (Bryn Keller)
> Thanks.
>
More information about the Python-list
mailing list