+ 8
Is it necessary to write type of error after 'except'??
2 Réponses
+ 2
A reduced way to get information about an exception is like that:
try:
value += 2
except Exception as e:
print('error occurred: ',e)
# output:
# error occurred: name 'value' is not defined
+ 1
If you don’t, it will catch all errors. This means that bugs can occur that you didn’t expect and an unexpected or incorrect output can be given. It is considered a good practice to write the possible errors out