added a catch for bad_alloc errors