/** * Handler to catch uncaught exception. * @param \Exception * @return void * @internal */ public static function _exceptionHandler(\Exception $exception) { if (!headers_sent()) { // for PHP < 5.2.4 $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::$consoleMode) { echo "ERROR: the server encountered an internal error and was unable to complete your request.\n"; } elseif (self::isHtmlMode()) { require __DIR__ . '/templates/error.phtml'; } } else { if (self::$consoleMode) { // dump to console echo "{$exception}\n"; if ($file = self::log($exception)) { echo "(stored in {$file})\n"; if (self::$browser) { exec(self::$browser . ' ' . escapeshellarg($file)); } } } elseif (self::isHtmlMode()) { // dump to browser self::$blueScreen->render($exception); if (self::$bar) { self::$bar->render(); } } elseif (!self::fireLog($exception)) { // AJAX or non-HTML mode $file = self::log($exception, self::ERROR); if (!headers_sent()) { header("X-Nette-Error-Log: {$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"; } } self::$enabled = FALSE; // un-register shutdown function exit(254); }
/** * Handler to catch uncaught exception. * @param \Exception * @return void * @internal */ public static function _exceptionHandler(\Exception $exception) { if (!headers_sent()) { // for PHP < 5.2.4 header('HTTP/1.1 500 Internal Server Error'); } try { if (self::$productionMode) { try { self::log($exception, self::ERROR); } catch (\Exception $e) { echo 'FATAL ERROR: unable to log error'; } if (self::$consoleMode) { echo "ERROR: the server encountered an internal error and was unable to complete your request.\n"; } elseif (self::isHtmlMode()) { require __DIR__ . '/templates/error.phtml'; } } else { if (self::$consoleMode) { // dump to console echo "{$exception}\n"; } elseif (self::isHtmlMode()) { // dump to browser self::$blueScreen->render($exception); if (self::$bar) { self::$bar->render(); } } elseif (!self::fireLog($exception, self::ERROR)) { // AJAX or non-HTML mode self::log($exception); } } 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"; } } self::$enabled = FALSE; // un-register shutdown function exit(255); }
/** * Handler to catch uncaught exception. * @param \Exception * @return void * @internal */ public static function _exceptionHandler(\Exception $exception) { if (!headers_sent()) { // for PHP < 5.2.4 header('HTTP/1.1 500 Internal Server Error'); } $htmlMode = !self::$ajaxDetected && !preg_match('#^Content-Type: (?!text/html)#im', implode("\n", headers_list())); try { if (self::$productionMode) { self::log($exception, self::ERROR); if (self::$consoleMode) { echo "ERROR: the server encountered an internal error and was unable to complete your request.\n"; } elseif ($htmlMode) { require __DIR__ . '/templates/error.phtml'; } } else { if (self::$consoleMode) { // dump to console echo "{$exception}\n"; } elseif ($htmlMode) { // dump to browser self::$blueScreen->render($exception); if (self::$bar) { self::$bar->render(); } } elseif (!self::fireLog($exception, self::ERROR)) { // AJAX or non-HTML mode self::log($exception); } } foreach (self::$onFatalError as $handler) { call_user_func($handler, $exception); } } catch (\Exception $e) { echo "\nNette\\Debug FATAL ERROR: thrown ", get_class($e), ': ', $e->getMessage(), "\nwhile processing ", get_class($exception), ': ', $exception->getMessage(), "\n"; } self::$enabled = FALSE; // un-register shutdown function exit(255); }