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(&quot;This is a note about the error&quot;)<br/> e.add_note(&quot;This is another note&quot;)<br/> e.add_note(&quot;All notes must be strings&quot;)<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