Forum: Ruby handle ArgumentError to resume loop at next iteration

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
De60a566d8e2a8dec790d1f6741ad424?d=identicon&s=25 jay (Guest)
on 2007-02-22 17:43

still a noob, and still hacking a script to traverse photo directories
to populate a mysql db with various photo metadata.  nearly there, but
having trouble handling an error from DateTime that dies on a file that
doesn't have 3 elements of a civil date.
can anyone recommend a way of handling this error so that the loop skips
to the next iteration?
code below.
many thanks in advance

find.find(directory) do |path|

  next if
  next unless path =~ /.jpg$/ or /.JPG$/

   puts "trying picture: #{path} "
#  get metadata
    pathName =  path
    baseName = File.basename(path)
    fileSize = File.size(path)
    cameraModel =
    picWidth =
    picHeight =
    picDateTaken =
      ^^^error point

    mysqlDate = DateTime.parse("#{picDateTaken}")
    picShutterSpeed =
    picAperture = #returns a fraction as
      aperture = picAperture.to_f
    focalLength =
    num+= 1

# => PRINT
    puts "added picture:  #{pathName} total pics:#{num}"

 db.query("INSERT INTO JPGS (name, path, size, model, width, height,
timeStamp, shutterSpeed, aperture, focalLength)
  VALUES ('#{baseName}', '#{pathName}', '#{fileSize}', '#{cameraModel}',
'#{picWidth}', '#{picHeight}', '#{mysqlDate}', '#{picShutterSpeed}',
'#{aperture}','#{focalLength}') ")

31ab75f7ddda241830659630746cdd3a?d=identicon&s=25 Austin Ziegler (austin)
on 2007-02-22 18:18
(Received via mailing list)
On 2/22/07, jay <> wrote:
rescue ArgumentError

This topic is locked and can not be replied to.