added a try-catch in template rendering