+ 2
is raising exceptions like creating our own exceptions? if no can someone explains to me "raising exceptions"?
2 ответов
+ 8
Not all the time. You have the choice to raise an already existing exception or raise your own.
E.g
if input () not in "0123456789":
raise ValueError("not a number")
else:print ("is a number")
or raising your own exception
class NotSeven (Exception):
def __init__(self):
Exception.__init__(self, "Input number is not seven")
if input () != "7":
raise NotSeven()
else:print ("Good, the number is seven.")
0
thank you 😀😀