Exception Methods

BaseException.add_note() — exception method

Attach additional diagnostic text without replacing the exception message or args. Repeated calls append notes in order; standard traceback formatting displays them after the exception. Supply a string, not an arbitrary object. Avoid putting credentials or personal data in diagnostic notes.

Formal Syntax & Structure

python syntaxpython
error.add_note(note, /)

Parameters & Attributes

NameTypeDescription
notestrAdditional diagnostic text.

Return Value

None

Mutates the exception; returns None.

Working Example

Example Snippetpython
error = ValueError("invalid quantity")print(error.add_note("row 4"))error.add_note("expected a positive integer")print(error.args)print(error.__notes__)
Python Reference