Use std::bad_alloc to indicate out-of-memory errors.