Ensure collection cleanup if an exception occurs.