Python Tip #289 (of 365): Add context to exceptions with add_note. def load_conf...

@treyhunner@mastodon.social

Python Tip #289 (of 365):

Add context to exceptions with add_note.

def load_config(path):
try:
return json.loads(Path(path).read_text())
except json.JSONDecodeError as error:
error.add_note(f"While parsing {path}")
raise

๐Ÿงต (1/4)

#Python #DailyPythonTip