TIL: #Python 3.11 introduced a new method called add_note for exceptions, which allows you to add extra information to exceptions in an easy, intuitive way. I've wanted this forever, didn't know I already had it.<br/>try:<br/> 1/0<br/>except ZeroDivisionError as e:<br/> e.add_note("This is a note about the error")<br/> e.add_note("This is another note")<br/> e.add_note("All notes must be strings")<br/> raise <br/>
Yields:
ZeroDivisionError: division by zero
This is a note about the error
This is another note
All notes must be strings
https://daniel.feldroy.com/posts/til-2025-05-exception-add_note via https://python.libhunt.com/newsletter/479