0

I have an API that raises ValueError():

def empty_string(foo):
    if foo == '':
        raise ValueError()
try:
    foo = ''
    empty_string(foo)
except ValueError as ex:
    print(f"{ex}")

How do I print what function raised the error? I am not in a position to change the API and make the exception arg more informative.

Tom Murley
  • 75
  • 1
  • 1
  • 8
  • 1
    Iterate through `sys.exc_info().tb_next` to find the last traceback, then take its `tb_frame.f_code.co_name` to get the function name. – Samwise May 21 '22 at 22:21

0 Answers0