For generic error catching, I prefer to catch logging.exception(), which will log your message along with the full stack trace of the current exception.
import loggingdef get_number():returnint('foo')try: x = get_number()except: logging.exception('Caught an error')
ERROR:root:Caught an error
Traceback (most recent call last):
File "/var/folders/70/7wmmf6t55cb84bfx9g1c1k1m0000gn/T/ipykernel_65386/3758161683.py", line 7, in <module>
x = get_number()
^^^^^^^^^^^^
File "/var/folders/70/7wmmf6t55cb84bfx9g1c1k1m0000gn/T/ipykernel_65386/3758161683.py", line 4, in get_number
return int('foo')
^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'foo'