# Beginner question exifr returns errors

**URL:** <https://www.ruby-forum.com/t/beginner-question-exifr-returns-errors/165429>\
**Category:** Ruby\
**Created:** [April 13, 2009, 10:55pm UTC](https://www.ruby-forum.com/t/beginner-question-exifr-returns-errors/165429 "2009-04-13T22:55:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmpmpm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b19c9b/32.png) [@pmpmpm](https://www.ruby-forum.com/u/pmpmpm)\
**Post date:** [April 13, 2009, 10:55pm UTC](https://www.ruby-forum.com/t/beginner-question-exifr-returns-errors/165429/1 "2009-04-13T22:55:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pmpmpm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b19c9b/32.png) [@pmpmpm](https://www.ruby-forum.com/u/pmpmpm)\
**Post date:** [April 14, 2009, 12:05am UTC](https://www.ruby-forum.com/t/beginner-question-exifr-returns-errors/165429/2 "2009-04-14T00:05:27Z")

</div>

On Mon, Apr 13, 2009 at 1:55 PM, pm [removed\_email\_address@domain.invalid](mailto: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,
