0

try: num = 5 / 0 except: print("An error occurred") raise

above code in tut having none output but as per tut it shud give result of exception.. need help in understanding

24th Apr 2017, 4:24 AM
arun kumar
arun kumar - avatar
3 Antworten
+ 3
It both prints "An error occurred" and raises an exception.
24th Apr 2017, 5:34 AM
Álvaro
+ 1
The code is okay with me, it's giving me the output " num = 5 / 0 ZeroDivisionError: division by zero", that's what expected. initially it handles the exception with help of "except:" and output "An error occured", and then again raise the exception with keyword raise. Remember : the "raise" will raise only that exception which is already in your code.
27th Apr 2017, 10:19 PM
Abraiz Khan
Abraiz Khan - avatar
0
bare exception... should use except ZeroDivisionError : ...
20th Feb 2022, 11:47 AM
Gurseerit Singh Chahal ✓
Gurseerit Singh Chahal ✓ - avatar