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?

20th Feb 2020, 4:49 AM
Ahmed Araby
Ahmed Araby - avatar
5 Respostas
+ 3
Please share your code
20th Feb 2020, 5:06 AM
Tanmay Gupta
Tanmay Gupta - avatar
+ 2
Use except statement to catch exception. try: print(1/0) except: print("error")
20th Feb 2020, 4:56 AM
A͢J
A͢J - avatar
+ 1
Hi, hard to help without code. Could you please link your code here?
20th Feb 2020, 4:56 AM
Oma Falk
Oma Falk - avatar
+ 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.
20th Feb 2020, 5:37 AM
XXX
XXX - avatar
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
20th Feb 2020, 4:18 PM
Ahmed Araby
Ahmed Araby - avatar