More robust handling of possible errors when using COM