Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to exception for invalid date ruby

Tags:

ruby

I want to know to what exception name I should refer to. I am getting invalid date. I checked the docs and I couldn't find it.

Begin
    Date.new(day,month,year)
Rescue exceptionname
    statements
like image 450
chirag7jain Avatar asked Aug 01 '13 02:08

chirag7jain


1 Answers

I think you're looking for ArgumentError. Using irb:

> Date.new(2,-200, 3)

ArgumentError: invalid date
    from (irb):11:in `new'
    from (irb):11

so

begin
    Date.new(2,-200, 3)
rescue ArgumentError
    #your logic
end
like image 119
nicosantangelo Avatar answered Oct 08 '22 16:10

nicosantangelo