Forum: Ruby beginner question exifr returns errors

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
pm (Guest)
on 2009-04-14 00:55
(Received via mailing list)
Hello everyone,

I've a piece of code that looks for 'jpeg' files and reads their exif
and then puts them into appropriate folders. Some times 'bad formated'
jpeg-files gives me a runtime error on the exifr call.

How can I avoid this ? In the case of a bad formated jpeg file I would
like to be able to read the next one, without interrupting the program

My code is :
---------------------------------------------------------

   if (File.stat(f).ftype == "file") and (f.include? ".jpg" or
f.include? ".JPG") then
       j = EXIFR::JPEG.new(f)

       if j.exif? then

         my_date  = j.date_time_original.to_s.split
         my_month = my_date[1]
---------------------------------------------------------


thanks for your answers
Hassan S. (Guest)
on 2009-04-14 02:05
(Received via mailing list)
On Mon, Apr 13, 2009 at 1:55 PM, pm <removed_email_address@domain.invalid> 
wrote:

> I've a piece of code that looks for 'jpeg' files and reads their exif and
> then puts them into appropriate folders. Some times 'bad formated'
> jpeg-files gives me a runtime error on the exifr call.
>
> How can I avoid this ? In the case of a bad formated jpeg file I would like
> to be able to read the next one, without interrupting the program

You can rescue the exception and log it, ignore it, whatever.

HTH,
This topic is locked and can not be replied to.