template.php: Add a TemplateException class

Issue #101.