I'm not sure how rescue it.  I copied in this code I found.  URI.parse(value).kind_of?(URI::HTTP) this returns false if a url is invalid and doesn't error.