How can I get where exactly in my code there was an error? I need to know if it was inside or outside a function and the absolute line number inside the script (or at least inside the function).
Looking at the very schematic example below this lines:
Let's say there's an error inside function func_b. I want to print: Error in func_b, line 4
Right now I'm using
sys.exc_info()[2].tb_lineno to get the line number, but it prints: Error in my_script.py, line 8 which is not what I want.
If there's an error before executing any function I want to print: Error in my_script.py, line 6
def func_a(): #do something def func_b(): #do something try: #do something func_a() func_b() except Exception as e: print(...) # print where error occurred.
print __file__, andprint __line__should work