Catch GDI exceptions which may happen

Since GDI and Windows applications don't seem to get along, GDI may
throw exceptions from time to time. This catches them.