+ 1

Q. Python Exception

except TypeError as e: print(e) Is it possible to do the same for except: So that i can get a brief description about the error.

20th Nov 2019, 8:34 AM
Abhishek Kumar
Abhishek Kumar - avatar
2 Antworten
+ 6
You can do it in a more general way, without naming each exception in detail: number = '3' try: result = number + 10 except Exception as e: print('Error:',e) # output: "Error: must be str, not int"
20th Nov 2019, 10:35 AM
Lothar
Lothar - avatar
+ 4
No, you can't. With last example you just detect existence of an error, but dont actually get it
20th Nov 2019, 9:19 AM
Savvasenok
Savvasenok - avatar