Wednesday, December 17, 2008

throwing exceptions should not be done ad-hoc

what would you expect from this code?


System.Drawing.Image.FromFile("file.mp3")


Notice that i deliberately pass a non-image file to this function. Do you expect you will get InvalidImageFormatException? I would expect that, but as Microsoft documentation says it will return OutOfMemoryException.

Since when out of memory has something to do with image format? That's a rhetoric question of course, since .Net2 is many years on the production already :)

No comments: