Why do you always wake up right before you’re about to die in a nightmare?

Why do we wake up right before we’re about to die in a dream? Our brains can’t process the idea of death and what might come after! Think about it, if you have a dream and you’re falling, you always wake up right before- this is crazy! Hopefully this doesn’t happen to you too often, but now you know why!