Source for file ErrorHandling.class.php
Documentation is available at ErrorHandling.class.php
* Error handling features
* @copyright 2009-2010 NADEO
* @subpackage ErrorHandling
* Error handling features and handlers
* @todo doc explain error handling strategy
* @subpackage ErrorHandling
protected static $messageConfigs =
array(
'title' =>
'$<$ff0$o%s$>',
'line' =>
' $<$ff0%s$> : %s'
* Converts standard PHP errors into ErrorException
* Usage (loaded by default in the MVC framework):
* set_error_handler(array('ErrorHandling', 'exceptionErrorHandler'));
throw
new ErrorException($errstr, 0, $errno, $errfile, $errline);
* Used to cleanly catch exceptions, and is also used as uncaught exception handler.
* Prints a nice error message in manialink
* Usage for catching exceptions:
* catch(Exception $exception)
* ErrorHandling::exceptionHandler($exception);
* Usage for default exception handling:
* set_exception_handler(array('ErrorHandling', 'exceptionHandler'));
* Note: the MVC framework uses both by default
$requestURI =
$request->createLink();
if($exception instanceof
UserException)
self::showErrorDialog($exception->getMessage());
$requestURILine =
sprintf(self::$messageConfigs['default']['line'], 'Request URI', $requestURI);
$message =
self::computeMessage($exception, self::$messageConfigs['default'], array($requestURILine));
$requestURILine =
sprintf(self::$messageConfigs['debug']['line'], 'Request URI', $requestURI);
$message =
self::computeMessage($exception, self::$messageConfigs['debug'], array($requestURILine));
self::showDebugDialog($message);
* Shows an error dialog to the user with the specified message
* @param The message to show, default is 'Fatal error'
static function showErrorDialog($message =
'Fatal error')
$linkstr =
$request->getReferer();
$ui->setAlign('center', 'center');
$ui->title->setStyle(Label::TextTitleError);
$ui->titleBg->setSubStyle(Bgs1::BgTitle2);
$ui->title->setText('Error');
$ui->enableAutonewline();
$ui->setAlign('center', 'center');
$ui->setPosition(0, 0, 2);
$ui->setManialink($linkstr);
$ui->setPosition(0, -
12, 5);
$ui->setHalign('center');
* Error dialog for debug, the panel is bigger to fit the whole exception log
* @param The message to show, default is 'Fatal error'
static function showDebugDialog($message =
'Fatal error')
$linkstr =
$request->getReferer();
$ui =
new Panel(124, 92);
$ui->setAlign('center', 'center');
$ui->title->setStyle(Label::TextTitleError);
$ui->titleBg->setSubStyle(Bgs1::BgTitle2);
$ui->title->setText('Error');
$ui->setAlign('left', 'top');
$ui->setPosition(-
60, 38, 2);
$ui->enableAutonewline();
$ui->setManialink($linkstr);
$ui->setPosition(0, -
40, 5);
$ui->setHalign('center');
* Computes a human readable log message from any exception
static protected function computeMessage(Exception $e, array $styles, array $additionalLines =
array())
$trace =
$e->getTraceAsString();
foreach ($trace as $key=>
$value)
$file =
sprintf($styles['simpleLine'], $e->getFile().
' ('.
$e->getLine().
')');
$lines[] =
sprintf($styles['line'], 'Message', print_r($e->getMessage(), true));
$lines[] =
sprintf($styles['line'], 'Code', $e->getCode());
$lines =
array_merge($lines, $additionalLines, array($file), $trace);
* Computes a short human readable log message from any exception
static protected function computeShortMessage(Exception $e)
$message =
get_class($e).
' '.
$e->getMessage().
' ('.
$e->getCode().
')';