Lousy GDI+ Error Messages

I have heard many people complaining about how GDI+ handles errors. It seems that many of the GDI+ error messages are either too broad to have any concrete meanings (e.g. "A generic error occurred in GDI+") or simply just misleading.

Trying to open an empty (0 byte) file of any type using  Image.FromFile(…) function in .Net  would result in an "Out of memory" exception.

The .Net Image.FromFile() function simply wraps around a GDI+ function GdipLoadImageFromFile and returns whatever error code the underlying function returns. And when an empty file is passed to the FromFile() function, the return code is 3 which translates into "Out of memory".

To me, this is really misleading, and I wonder how many developers had been scratching their heads trying to figure out what went wrong with their code when prompted with this error message. I wish Microsoft could have changed it to something more meaningful and in this case something like "Invalid image header" or "Invalid image file format"?

Be Sociable, Share!

Leave a Reply