Variables in error pages


I want to make my own error pages with some variables, because
description of the errors may vary.
How can I make this? As far as I know, I can only place static html in
/public folder.

I just want to raise 500 error with custom error message - this is the
main aim.