Suggestions on error

Note: this is about version 3.0.1, currently in dev as time of writing.

As you know the error handler (PHPDS_errorHandler) will catch any error or uncaught exception happening within your code. What you may not know is that you can provide more info / suggestions to the site admin when such errors arise.

To understand what you can do, take a look at this code:

class PHPDS_sprintfnException extends PHPDS_exception
{

	public function __construct($message = "", $code = 0, $previous = null) // CAUTION this declaration is NOT correct
	{
		$msg = '

The faulty string source is:
<pre class="ui-state-highlight ui-corner-all">'.htmlentities($message).'</pre>
'; if (!empty($code)) $msg .= 'The parameters were:<br />'.PU_dumpArray($code, null, true).'

'; parent::__construct($msg, 0, $previous); } public function hasCauses() { return true; } public function getCauses() { $result = array( 'Unable to build a string with sprintfn', array( array('Some template or theme file has altered a module which does comply to the given parameters.', 'Try a different theme or check for possible typos in the theme module list') ) ); return $result; } }

This exception is throw when an error occurs in the PU_sprintfn() utility function. Take a look at the getCauses() method. It simply returns an array: for each possible cause, it provides a suggestion about what's wrong and what you can do about it. The error handler will nicely format that and put it on the top of the error page.

This is especially usefull when you're writing code which will be used by others (such as plugin).

PHPDevShell © 2010 - All rights reserved.