Pilots are trained to prepare for things not going to plan throughout every single flight, so that they are able to make split-second decisions and keep passengers safe, a pilot could go through their whole career without dealing with an incident like this but if it happens all the training and time in the simulator pays off.