Meningkatkan pengecualian di Python
>>> raise KeyboardInterrupt
Traceback (most recent call last):
...
KeyboardInterrupt
>>> raise MemoryError("This is an argument")
Traceback (most recent call last):
...
MemoryError: This is an argument
>>> try:
... x = int(input("Enter a positive integer: "))
... if x <= 0:
... raise ValueError("That is not a positive number!")
... except ValueError as y:
... print(y)
...
Enter a positive integer: -2
That is not a positive number!
Outrageous Ostrich