I have an external dll that provides the time and date a photo has been taken

I am getting an argumentexception for a certain image. I believe it is because it is a jpeg from a scan, so it doesn't have a datetime.

My problem is that even with the call being in a try/catch statement, the error stops the program before it goes to the catch. Is there any way I can prevent this.

                 //check for datetakentag if present return datetime taken
                 string dateTakenTag = null;
            dateTakenTag = Encoding.ASCII.GetString(img.GetPropertyItem(DATE_TAKEN_TAG_ID).Value); 
catch (ArgumentException e)
                    int year = Curr.Year;  etc.

Is this a managed or unmanaged DLL? What class is 'img'?

Have you tried catching ExternalException instead of ArgumentException?

I'm not sure about the managed unmanaged issue, it's just a dll I wrote myself witha few functions handling photos.

Just tried externalexception in the dll itself? But it still has the same problem. Should I use the externale4xception in the calling routine, rather than the one I am calling.

using (Image img = Image.FromFile(imagefileName))
I think this makes it an image class.

In the calling routine

I have tried that but the program keeps stopping in the dll.
The strange part is that if I step thru it will stop, and then go to the catch statement on the next step.

But while it's running the program crashes. The routine works fine with most pictures, but as I said before I don't think the scanned image has that property.

What I can't understand is why a try statement doesn't work.

I finally solved it, albeit by a quick and dirty way.
I am putting my solution here for anyone that has a similar problem.
I researched and could not find a way to stop an exception being thrown in the try statement which stopped the code.

I then thought maybe I can test for the condition that stops the code.
When I looked at the number of Image.PropertyItems in a normal photo there were 52, I checked the offending picture it had two, so I checked the Image.PropertyItems.Length and if it was under say 40 I would not try to get the property item, over 40 it was ok the program wouldn't crash.
Thanks to Momerath for his/her suggestions.