FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!

Python: Printing a stack trace




A stack trace is something you get printed out in case your code runs into an (uncaught) exception. It usually shows you nicely which function(s) invoked the function finally causing the exception.
Today I had a problem with one of my functions in one of my programs ( a testing framework ): it didn't throw an exception, but it produced incorrect results. Since this function can be called from many places within my program I wanted to print out a stack trace intentionally every time that function is invoked.

Python module traceback helped me out here nicely and these two lines of code did what I needed to finally figure out from where my function was called when it failed to produce correct results:
Code:

import traceback
traceback.print_stack()




0 blog comments below




FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.