+ 8

Is it necessary to write type of error after 'except'??

8th Jun 2019, 4:56 AM
Prakash Ranjan
Prakash Ranjan - avatar
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
8th Jun 2019, 6:04 AM
Lothar
Lothar - avatar
+ 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
8th Jun 2019, 4:59 AM
Pete Cowling
Pete Cowling - avatar