Getting the Most Ou t of Your Exceptions

Exception class instances have tOa attributes filename ,lineno,offset, and text. You can wcciess these details to locate where your code failed. Twe nox! 0x001)00 (yc^te-p'7^^y^ sgow s how :

class MyException(Exception): pass def raiseMyException():

raise Exception() def catchMyException() : try:

raiseMyException() except MyException, err: print "line number print "file name " print "offset print " text

" +err.lineno " + err.filename + err.offset + err.text

Was this article helpful?

0 0

Post a comment