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

Pubblicato il: 03 luglio 2022
sul canale di: 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))


In questa pagina del sito puoi guardare il video online 25. Raise in Python Example || Raise Statement Exception Handling Python Programming Tutorial della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Bhavatavi 03 luglio 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 14 volte e gli è piaciuto 1 spettatori. Buona visione!