I don't understand the question entirely, but if you're after a way of handling error, particularly unhandled ones nicely, then you want Structured Error Handling.
This presentation is old, but gives a good starting point: https://pugchallenge.org/downloads2015/272_Strucutred_Error_Handling.pdf