Tag: handling

Nothing in life is as important as you think it is, while you are thinking about it.

Python – Error Handling 2

Hi all, here are more examples for error handling. my_value = 10 try: print(1 / my_value) print(“No error occurred!”) except NameError: print(“A NameError occurred!”) except ZeroDivisionError: print(“A ZeroDivisionError occurred!”) except TypeError: print(“A TypeError occurred!”) print(“Done!”) We catch three error types. try: print(undeclared_variable) #—> cause of a NameError print(1 / 0) #—> cause of a ZeroDivisionError…
Read more

Python – Error Handling 1

Hi all, here are the samples for error handling with try/catch. my_value = “0” try: print(10 / my_value) except ZeroDivisionError: print(“Can’t divide by zero”) except: print(“Not possible”) When you run the code, here is the output Not possible my_value = 0 try: print(10 / my_value) except ZeroDivisionError: print(“Can’t divide by zero”) except: print(“Not possible”) When…
Read more