Printing an exception is defined as printing the exception message, which currently is e.args[0]. We will not change that as it would break code worldwide. To print more, the class name can be used directly or as a key into a dict of replacements or replacement functions.
Questions and vague ideas should be directed to python-list. Fleshed out ideas can go to python-ideas.
>>> {}['d']
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
{}['d']
KeyError: 'd'
>>> try:
{}['d']
except Exception as e:
print(e)
'd'
>>> try:
{}['d']
except Exception as e:
print(e.args)
('d',)
>>> try:
{}['d']
except Exception as e:
print(f'{e.__class__.__name__}: {e}') # Reproduce standard report.
KeyError: 'd'
|