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. The raise keyword raises an error and stops the control flow of the program.
Code:
def division_try(number):
try:
if number==13:
raise ValueError("ValueError #1: Number 13!")
return 100/number
except ZeroDivisionError:
return"ZeroDivisionError: any number but zero."
except TypeError:
return "TypeError: failed to divide by numerical value."
except ValueError:
print("ValueError #2: 13 is not a favorite number.")
raise
for val in (0,"hello",50.2,13):
print("Testing %s: " % val, end="\n")
print(division_try(val))
On this page of the site you can watch the video online 25. Raise in Python Example || Raise Statement Exception Handling Python Programming Tutorial with a duration of hours minute second in good quality, which was uploaded by the user Bhavatavi 03 July 2022, share the link with friends and acquaintances, this video has already been watched 14 times on youtube and it was liked by 1 viewers. Enjoy your viewing!