+ 1
Why do we get ZeroDivisionError also as output for the code:
Is not it supposed to be skipped? try: print(1/ 0) except ZeroDivisionError: raise ValueError
3 Respostas
+ 2
The problem is that during handling of the ZeroDivisionError that is caused by 1/0, another exception is raised (the ValueError you raise in the last line). try/catch is supposed to catch exceptions, not to produce more or other kinds of exceptions. Thus python informs you that during handling of the ZeroDivisionError another exception (of type ValueError) is raised. This is supposed to enable you to trace back where the "original" exception (ZeroDivisionError) happened. The Python interpreter tries to help you by reconstructing the whole "chain" of exceptions.
+ 1
try/except is called try/catch in other languages, that's why I wrote try/catch. The pattern is the same: you "try" something and if an exception is raised, you "catch" it. If you don't catch an exception, the program will just show an error message and stop. With an except statement, you can tell the program what to do when an exception occurs. In your except statement, you raise yet another exeption which isn't handled. That's why the program stops. The rest is explained in my first post
0
I still don't get it? What are u talking about try/catch, I did not use that. Otherwise, except skips the errors and does not show, then why not here?