ruby/ruby — pull request #173 by binarycleric (2012-08-30 03:23:57+00:00)
Title: Added meaningful exceptions to IPAddr

At my day job we are doing some processing of an incoming IP address / host name in a Rails middleware and I noticed that the IPAddr class would always raise `ArgumentError` with only the error message giving any clue as to the cause.

I needed to be able to programmatically determine to cause of the failure to determine how to procede. Matching against the error message was less than ideal so modifying the Exceptions in seemed to be the most logical course of action.

With new exceptions a developer can pragmatically determine the cause of the IPAddr failure in a more effective manor than checking the exception message.

## Previously

```ruby
begin
ip = IPAddr.new(some_other_variable)
rescue ArgumentError => e
# Can't programmatically determine cause of the failure
end
```

## With Patch

```ruby
begin
ip = IPAddr.new(some_other_variable)
rescue IPAddr::InvalidAddress => e
rescue IPAddr::UnsupportedAddressFamily => e
rescue IPAddr::UnsupportedAddressFamily => e
rescue IPAddr::ZeroFilledNumber => e
# can use the exception to determine cause of the failure.
end
```