python 3 try-except all with error [duplicate]
Yes you can catch all errors like so:
try:
print(555)
except Exception as e:
print("type error: " + str(e))
For the stack trace I usually use the traceback module:
import traceback
try:
print(555)
except Exception as e:
print("type error: " + str(e))
print(traceback.format_exc())
You can do:
try:
print(555)
except Exception as err:
print("Erro {}".format(err))
Or use raise
Docs are always your friend
Tip: Avoid use "except:"
Use something more descriptive like
...
except (ValueError, KeyError):
Unless your code is very well tested, you can't figure out every error.