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))
En esta página del sitio puede ver el video en línea 25. Raise in Python Example || Raise Statement Exception Handling Python Programming Tutorial de Duración hora minuto segunda en buena calidad , que subió el usuario Bhavatavi 03 julio 2022, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 14 veces y le gustó 1 a los espectadores. Disfruta viendo!