chirag7jain
chirag7jain

Reputation: 1537

how to exception for invalid date 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

Upvotes: 5

Views: 4834

Answers (1)

nicosantangelo
nicosantangelo

Reputation: 13716

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

Upvotes: 11

Related Questions