Monday, May 26, 2008

Throw Exceptions Responsibly

Recently I had to spend some time to fix a crash in the application I'm working on: I kept getting an OutOfMemoryException with no relation to the amount of free memory on the computer.

Eventually I found the bug: turns out the DrawArc method doesn't like to be called with a very small angle, so it goes BOOM.

Another tidbit I found while searching for the cause was the fact this behavior is not unique to this method:

"The thing I can add about this is that GDI+ tends to throw OutOfMemoryException when something else is going on. I've seen people complaining about this in the newsgroups and elsewhere on the internet.

So we have here a framework with the habit to fail very un-responsibly.

Hmm, why does that sounds familiar?

Somehow I get the feeling that while Microsoft employ 50 people to handle a single feature, no one is left to take care of exceptions and errors in their products.

(in the photo: Windows Vista security exception)

1 comment:

Yuhong Bao said...

It isn't just Microsoft code that do this. In Raymond Chen's book there is a section about how "Out of memory" is the generic error message for many applications.