0
raise
I tried the raise statement but the output gave an error:" Traceback (most recent call last): File "/Paython/except_raise.py", line 4, in <module> print(num1/num2) ZeroDivisionError: division by zero Did that mean the raise was not recognized by the program? what can be the reason?
5 Respostas
+ 3
Please share your code
+ 2
Use except statement to catch exception.
try:
print(1/0)
except:
print("error")
+ 1
Hi,
hard to help without code.
Could you please link your code here?
+ 1
If you did something like
raise ZeroDivisionError("division by zero")
then the output is perfectly legit. Raise statement literally raises an error, it doesn't just print out the error. And I hope you're not confusing except with raise.
0
That is what I want
I thought it will not produce an error message like except
I simply used the following
try:
num = 5 / 0
except:
print("An error occurred")
raise