create your own type of exception if you wanted to. : Your Exception « Development « Ruby






create your own type of exception if you wanted to.


class BadDataException < RuntimeError
end

class Person
  def initialize(name)
    raise BadDataException, "No name present" if name.empty?
  end
end

 








Related examples in the same category

1.Ruby exception hierarchy
2.if we create our own exception classes, they need to be subclasses of either class Exception or one of its descendants.