Location: PHPKode > scripts > Template Processor > template-processor/example_errorhandling.php
<?php
	/**
	 * New error handler introduced in v1.0.2, notice the new class name as of v1.0.2 also
	 */

	/**
	 * Declare a class with an error function
	 */
	class ErrorHandler
	{
		function ErrorHandler($message)
		{
			die('<h3>Template Error from class method</h3><pre>' . $message . '</pre>');
		}
	}

	/**
	 * Declare an error function
	 */
	function ErrorHandler($message)
	{
		die('<h3>Template Error from function</h3><pre>' . $message . '</pre>');
	}

	/**
	 * Load template class
	 */
	require('./template.class.php');

	/**
	 * Init template class
	 */
	$template = new Template(Array('ext' => 'php'));

	/**
	 * Set error handler method to the function reference
	 */
	$template->set_error_handler(Array('type' => 'function', 'function' => 'ErrorHandler'));

	/**
	 * Generate an error
	 */
	$template->set_option('foo', 'bar');

	/**
	 * This will print something like:
	 *
	 *	<h3>Template Error from function</h3>
	 *	<pre>Trying to define a not allowed option!</pre>
	 *
	 */

	/**
	 * Now we want to use the class with an error function aka. method to handle our error
	 */

	/**
	 * Set error handler method to the class reference
	 */
	$template->set_error_handler('type' => 'object', 'object' => 'ErrorHandler', 'function' => 'ErrorHandler'));

	/**
	 * By making a new error again...
	 */
	$template->set_option('bar', 'foo');

	/**
	 * ... will cause the error handler to be triggered and generate this output:
	 *
	 *	<h3>Template Error from class method</h3>
	 *	<pre>Trying to define a not allowed option!</pre>
	 *
	 */
?>
Return current item: Template Processor