There is a pyramid setting to catch mako exceptions.
A small pyramid extensions targeting mako exceptions in pyramid.
If you want to get in touch with mako rendering method directly, you can go for a mako preprocessor.
sample code for this approach.