Raise exception from constructor : raise « Statement « Ruby
- Ruby
- Statement
- raise
Raise exception from constructor
class Person
def initialize(name)
raise ArgumentError, "No name present" if name.empty?
end
end
fred = Person.new('')
Related examples in the same category