Location: PHPKode > projects > SithTemplate > SithTemplate-1.1/docs/html/09_errors_8php-example.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>SithTemplate: 09_errors.php</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.2 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<h1>09_errors.php</h1>  </div>
</div>
<div class="contents">
<p>An example showing error handling.</p>
<div class="fragment"><pre class="fragment">&lt;?php
require_once <span class="stringliteral">&#39;SithTemplate.php&#39;</span>;

$environ = <span class="keyword">new</span> <a name="_a0"></a><a class="code" href="class_template_environ.html" title="Template environment - library&amp;#39;s end-user API.">TemplateEnviron</a>;

<span class="comment">// You should always remember about error handling</span>
<span class="comment">// If error occurs during template compilation, exception message</span>
<span class="comment">// may contain template file and approx. line of the mistake.</span>

<span class="comment">// Errors are grouped - every group has it&#39;s own errorcode, specified</span>
<span class="comment">// as class constants in TemplateError.</span>
<span class="keywordflow">try</span> {
 $environ-&gt;<a name="a1"></a><a class="code" href="class_template_environ.html#a564c04dff7b3d6d026ae07adf64dc8b2" title="Render the template directly.">render</a>(<span class="stringliteral">&#39;string://{% bkock foo %}Typos are evil.{% endblock %}&#39;</span>, array());
} <span class="keywordflow">catch</span> (<a name="_a2"></a><a class="code" href="class_template_error.html" title="Main and currently the only exception type thrown by SithTemplate internals.">TemplateError</a> $e) {
 echo $e-&gt;getMessage(); <span class="comment">// Unknown tag ...</span>
 echo $e-&gt;getCode();    <span class="comment">// TemplateError::E_UNKNOWN_TAG</span>
}
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Fri Jan 14 2011 20:08:36 for SithTemplate by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
Return current item: SithTemplate