Example #1
0
 /**
  * Enables displaying or logging errors and exceptions.
  * @param  mixed         production, development mode, autodetection or IP address(es) whitelist.
  * @param  string        error log directory; enables logging in production mode, FALSE means that logging is disabled
  * @param  string        administrator email; enables email sending in production mode
  * @return void
  */
 public static function enable($mode = NULL, $logDirectory = NULL, $email = NULL)
 {
     parent::enable($mode, $logDirectory, $email);
     self::$blueScreen = self::getBlueScreen();
     self::$bar = self::getBar();
     self::$logger = self::getLogger();
     self::$fireLogger = self::getFireLogger();
     self::$consoleColors =& Tracy\Dumper::$terminalColors;
 }
 /**
  * Returns catched error/warning message.
  * @param  \ErrorException  catched error
  * @return bool
  */
 public static function catchError(&$error)
 {
     if (!self::$enabled && self::$lastError !== FALSE) {
         restore_error_handler();
     }
     $error = self::$lastError;
     self::$lastError = FALSE;
     return (bool) $error;
 }
Example #3
0
 /** @deprecated */
 public static function catchError(&$error)
 {
     trigger_error(__METHOD__ . '() is deprecated; use own error handler instead.', E_USER_DEPRECATED);
     if (!self::$enabled && self::$lastError !== FALSE) {
         restore_error_handler();
     }
     $error = self::$lastError;
     self::$lastError = FALSE;
     return (bool) $error;
 }
Example #4
0
tryError(){if(!self::$enabled&&self::$lastError===FALSE){set_error_handler(array(__CLASS__,'_errorHandler'));}self::$lastError=NULL;}static
function
catchError(&$error){if(!self::$enabled&&self::$lastError!==FALSE){restore_error_handler();}$error=self::$lastError;self::$lastError=FALSE;return(bool)$error;}static
Example #5
0
 /**
  * Handler to catch uncaught exception.
  * @param  \Exception
  * @return void
  * @internal
  */
 public static function _exceptionHandler(\Exception $exception, $shutdown = FALSE)
 {
     if (!self::$enabled) {
         return;
     }
     self::$enabled = FALSE;
     // prevent double rendering
     if (!headers_sent()) {
         $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
         $code = isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ') !== FALSE ? 503 : 500;
         header("{$protocol} {$code}", TRUE, $code);
     }
     try {
         if (self::$productionMode) {
             try {
                 self::log($exception, self::ERROR);
             } catch (\Exception $e) {
                 echo 'FATAL ERROR: unable to log error';
             }
             if (self::isHtmlMode()) {
                 require __DIR__ . '/templates/error.phtml';
             } else {
                 echo "ERROR: the server encountered an internal error and was unable to complete your request.\n";
             }
         } else {
             if (!connection_aborted() && self::isHtmlMode()) {
                 self::getBlueScreen()->render($exception);
                 self::getBar()->render();
             } elseif (connection_aborted() || !self::fireLog($exception)) {
                 $file = self::log($exception, self::ERROR);
                 if (!headers_sent()) {
                     header("X-Nette-Error-Log: {$file}");
                 }
                 echo "{$exception}\n" . ($file ? "(stored in {$file})\n" : '');
                 if (self::$browser) {
                     exec(self::$browser . ' ' . escapeshellarg($file));
                 }
             }
         }
         foreach (self::$onFatalError as $handler) {
             call_user_func($handler, $exception);
         }
     } catch (\Exception $e) {
         if (self::$productionMode) {
             echo self::isHtmlMode() ? '<meta name=robots content=noindex>FATAL ERROR' : 'FATAL ERROR';
         } else {
             echo "FATAL ERROR: thrown ", get_class($e), ': ', $e->getMessage(), "\nwhile processing ", get_class($exception), ': ', $exception->getMessage(), "\n";
         }
     }
     if (!$shutdown) {
         exit(254);
     }
 }