Someone could prepare for the possibility of such an event happening in the future in several ways.
1) Search for possibly Earth-crossing asteroids and study their orbits to calculate when and if they might someday collide with Earth. Thanks to people like Eugene Shoemaker we are already doing that.
2) Discuss ways and methods of diverting asteroids calculated to impact on Earth. We are doing that already.
3) Prepare for a failure to divert an incoming asteroid, and for other types of possible potential extinction events, by building arcologies.
An arcology is a structure that could serve as a potential ark to save humanity by containing an entire artificial enclosed ecosystem inside. The goal of an arcology would be to totally recycle all of the matter inside so that all the waste matter is turned into useful matter to be reused for the inhabitants.
So a moon base totally separated from the outside vacuum on the Moon would be an example of an arcology. And of course a moon base like arcology could be built anywhere, on the Moon, on Mars, on an asteroid, on a moon of another planet, in a totally constructed space habitat, etc., etc., with various modifications to the design to allow for local conditions.
And a moon base like arcology could be built on Earth, of course.
And if ensuring that mankind survives a potential extinction event on fragile little Earth by colonizing the Solar System so that Earth is not the only place where humans live is a goal, then building moon base like arcologies on Earth as practice for building arcologies on other worlds and in space habitats makes a lot of sense.
Practice makes perfect, as they say, and no doubt it will take a lot of practice to gradually prefect moon base like arcologies so that they are self sufficient, or at least self sufficient enough that the amount of resources they need to gather in outer space via asteroid mining, etc., will be doable.
So no doubt a lot of practice building arcologies on Earth will be necessary for the design of sufficiently self sufficient arcologies for outer space. So once the first few sufficiently advanced arcologies are built on Earth, at least the populations of those arcologies would survive an extinction level event (except for those arcologies that were two close to the impact and were destroyed).
And once the first few sufficiently advanced and self sufficient arcologies are built on Earth and in space, it would be logical to pass laws strongly encouraging more and more people to move into self sufficient arcologies on Earth and in space. As more and more people move into such moon base like arcologies a larger and larger proportion of Earth's population will be more or less safe from an extinction level impact or other type of terrible disaster.
The eventual goal would be to have everyone on Earth live in a moon base like arcology so that they would have no need of an outside ecosystem and could survive a massive asteroid impact or a super volcano eruption or other terrible natural disaster. Of course everyone living in outer space would live in a moon base like arcology until and unless some worlds in the Solar System are eventually terraformed to have a naturally habitable environment.
So it should be obvious that the way to prevent the extinction of all life on Earth, or at least all humans, is to begin preparing for a giant asteroid collision or a super volcano eruption or other natural extinction event before it happens, and even before it is first calculated to happen at a specific future date. It is best to prepare for such an event when no such event is predicted for specific future date, in order to have as much possible time to prepare in before that event happens.
It is better to begin preparing years instead of months before it happens, decades instead of years before it happens, centuries instead of decades before it happens, and millennia instead of centuries before it happens.
So if a giant asteroid sneaks past our detection system and strikes Earth unexpectedly, the proportion of the human race that survives will depend on on long and how well humans have been preparing for the general possibility of a catastrophic natural disaster.
Reacting to a specific asteroid that is predicted to strike hours, days, weeks, months, or years in the future will save only a tiny proportion of the population who could be saved if people begin preparing for the general possibility of such a disaster decades, centuries, or millennia before they know about that specific asteroid.