How can I modify a Python traceback object when raising an exception?

You can remove the top of the traceback easily with by raising with the tb_next element of the traceback:

except:
    ei = sys.exc_info()
    raise ei[0], ei[1], ei[2].tb_next

tb_next is a read_only attribute, so I don’t know of a way to remove stuff from the bottom. You might be able to screw with the properties mechanism to allow access to the property, but I don’t know how to do that.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)