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)
> 
import xml.parsers.expat

That way the interpreter will be able to resolve the reference to the 
exception.

> Also, how do I get the line number where an exception was thrown?
> 
#
# Exception traceback test
#
def r():
   return 1/0

try:
   print r()
except:
   import sys
   t, v, tb = sys.exc_info()

print "exception on line", tb.tb_lineno

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to