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
3 Respuestas
+ 3
It both prints "An error occurred" and raises an exception.
+ 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.
0
bare exception... should use except ZeroDivisionError : ...