Added exception handling in templates