Catch out of memory errors to prevent the GUI from getting stuck.