I'm just writting an Exception, which should stores a Class
object as a field for the error message process.
class BadType < Exception
getter should_be : Class
getter actual : Class
end
def feed(pet : Animal, food : Food)
raise BadType.new should_be: Cat, actual: pet.class if food == "fish" && !pet.is_a?(Cat)
end
But, Class
is abstract so cannot be used here as a field type.
So, how to solve this in my case? I hadn't found any derived class of Class
, so does it mean one can never store a Class
object as a field? But here my problem is a meaningful usage for this (any type check depends on input may require this BadType
).
I'm not sure whether I missed something, so I came here first.