As a Python developer you can choose to throw an exception if a condition occurs.
To throw (or raise) an exception, use the raise
keyword.
Raise an error and stop the program if x is lower than 0:
x = -1
if x < 0:
raise Exception("Sorry, no numbers below zero")
Try it Yourself »The raise
keyword is used to raise an exception.
You can define what kind of error to raise, and the text to print to the user.
ExampleRaise a TypeError if x is not an integer:
x = "hello"
if not type(x) is int:
raise TypeError("Only integers are allowed")
Try it Yourself »Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4