Not sure if this is all you need, but have tried this? def main(): #define vars try: foo(a, b, c) except IndexError: import traceback traceback.print_exc()