raise ArgumentError : raise « Statement « Ruby






raise ArgumentError


def join_to_successor(s)
  raise ArgumentError, 'No successor method!' unless s.respond_to? :succ
  return "#{s}#{s.succ}"
end

join_to_successor('a')                # => "ab"
join_to_successor(4)                  # => "45"
join_to_successor(4.01)
# ArgumentError: No successor method!

 








Related examples in the same category

1.Raising Exceptions
2.Raise exception from constructor
3.raise one on your own with the raise method from Kernel
4.Raise IndexError