I created a class, that accepts an argument, and when the type of this argument is not string, it raises an exception. Well, it raises the exception when I want to create an object of this class and the argument is not string, but it creates the object anyway. Is there any way to prevent object from creation?
class Movie():
def __init__(self, name):
if type(name) != str:
raise Exception("name should be string")
else:
self.name = name
movie = Movie(1)
Here I get the exception but if I print(movie)
, I get the location of the object in the memory. I want to get an error, that this name is not defined. Thanks in Advance.