25. Raise in Python Example || Raise Statement Exception Handling Python Programming Tutorial

Publié le: 03 juillet 2022
sur la chaîne: Bhavatavi
14
1

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))


Sur cette page du site, vous pouvez voir la vidéo en ligne 25. Raise in Python Example || Raise Statement Exception Handling Python Programming Tutorial durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Bhavatavi 03 juillet 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 14 fois et il a aimé 1 téléspectateurs. Bon visionnage!