Python exceptions handle
exceptions()
occur when an expression cannot be executed correctly while the syntax is correct.
>>> x = 0 >>> y = 5/x#5 cannot be divided by 0
Traceback (most recent call last): File "", line 1, in ZeroDivisionError: division by zero
In order to avoid the annoying output, and prevent potential exceptions, let's try exception handling:
>>> try: ... x=0 ... y=5/x ... except: ... print("Error") ...
Error