According to the wiki, heirs have considerably lower death rates than rulers if you don't make either of them into a general, whereas their life expectancies as generals are very similar.
On the other hand, there are several random events that kill your heir; probably this is the leading cause of death for young heirs who are not generals. Apparently there's one where your monarch has a 33% chance of death, but the circumstances in which it can be triggered are pretty rare. Other than that, you're never forced to risk your monarch's life by random event as far as I know (although a few of them give you the option to kill your monarch).