Python verhoog Sleutelwoord
Voorbeeld
Maak 'n fout en stop die program as x laer as 0 is:
x = -1
if x < 0:
raise Exception("Sorry, no numbers below
zero")
Definisie en gebruik
Die raise
sleutelwoord word gebruik om 'n uitsondering te maak.
Jy kan definieer watter soort fout om te maak, en die teks om aan die gebruiker te druk.
Meer voorbeelde
Voorbeeld
Verhoog 'n TypeError as x nie 'n heelgetal is nie:
x = "hello"
if not type(x) is int:
raise TypeError("Only
integers are allowed")