Skip to content

Instantly share code, notes, and snippets.

@nonchris
Created November 4, 2023 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nonchris/1888ac5c6dc86b9f56f6ffd4942a021a to your computer and use it in GitHub Desktop.
Save nonchris/1888ac5c6dc86b9f56f6ffd4942a021a to your computer and use it in GitHub Desktop.
might be helpful for someone
# might be useful for someone - but traceback.format_exc() is honestly better
# but this version gives at least some understanding of whats happening
def exec_location_info():
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback_details = tb.extract_tb(exc_traceback, limit=None)
last_call = traceback_details[-1]
rel_path = os.path.relpath(last_call.filename)
return (f"{exc_type.__name__}: '{exc_value}', "
f"file: {rel_path}, "
f"line: {last_call.lineno} '{last_call.line}', "
f"function: {last_call.name}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment