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))
Nesta página do site você pode assistir ao vídeo on-line 25. Raise in Python Example || Raise Statement Exception Handling Python Programming Tutorial duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Bhavatavi 03 Julho 2022, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 14 vezes e gostou 1 espectadores. Boa visualização!