Exception in Python Exception Class's __str__ Missed -


does know how catch exceptions in python exception's derived classes's __str__ function? , how debug __str__ using pdb since find doesn't work when invoke pdb.set_trace() or setting breakpoint in pdb in function __str__.

example code:

class ex(exception):     def __str__(self):         raise keyerror('1')  raise ex() 

the output is

traceback (most recent call last):   file "./exex.py", line 10, in <module>     raise ex() __main__.ex 

while think output should

keyerror: '1' 

and if add pdb.set_trace() before raise keyerror('1'), python runtime not interrupt @ pdb.set_trace(). know how debug exception.__str__ when little complex?


sorry pdb.set_trace() case. works. however, if forget put import pdb, python ignore exception looks pdb.set_trace() ignored.

while setting breakpoint in pdb still not work.

you don't need override __str__ message. do:

class ex(exception):    pass  raise ex('key error 1') 

prints:

traceback (most recent call last):   file "untitled.py", line 4, in <module>     raise ex('key error 1') __main__.ex: key error 1 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -