-2

I'm writing a program to validate CSV files in Ruby but I seem to not be using rescue correctly. I made sure to include the begin keyword. I'm using ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]

The code is here:

def self.validate
    begin
      CSV.foreach(@@filepath, headers: true) do |row|
    rescue CSV::MalformedCSVError
      return row
    end
    return -1
end

It's probably something silly, but I'm not sure what as I have the begin keyword included.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Barn on a Hill
  • 359
  • 3
  • 10

1 Answers1

0

You'll need one end for the do block, one for rescue and one for self.validate.

If you use a text editor which can indent your code, it's easy to see the problem :

def self.validate
  begin
    CSV.foreach(@@filepath, headers: true) do |row|
    rescue CSV::MalformedCSVError
      return row
    end
    return -1
  end

If your editor cannot do it, find a better one! ;)

Eric Duminil
  • 52,989
  • 9
  • 71
  • 124