/** * Exception handler * * Log exceptions in the application log file and print them to the screen * if "display_errors" is set. Callback to a custom exception handler defined * in the application file "config/error.php". * @param Exception */ function __exception($e) { error_log(sprintf("PHP Fatal error: Uncaught exception '%s' with message '%s' thrown in %s on line %s", get_class($e), $e->getMessage(), $e->getFile(), $e->getLine())); // Display the exception if (ini_get('display_errors')) { $strMessage = sprintf('<strong>Fatal error</strong>: Uncaught exception <strong>%s</strong> with message <strong>%s</strong> thrown in <strong>%s</strong> on line <strong>%s</strong>', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()); $strMessage .= "\n" . '<pre style="margin:11px 0 0">' . "\n" . $e->getTraceAsString() . "\n" . '</pre>'; echo '<br>' . $strMessage; } show_help_message(); exit; }
/** * Exception handler * * Log exceptions in the application log file and print them to the screen * if "display_errors" is set. Callback to a custom exception handler defined * in the application file "config/error.php". * * @param Exception|Throwable $e */ function __exception($e) { // PHP 7 compatibility if (!$e instanceof Exception && (!interface_exists('Throwable', false) || !$e instanceof Throwable)) { throw new InvalidArgumentException('Exception or Throwable expected, ' . gettype($e) . ' given'); } error_log(sprintf("PHP Fatal error: Uncaught exception '%s' with message '%s' thrown in %s on line %s\n%s", get_class($e), $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString())); // Display the exception if (ini_get('display_errors')) { $strMessage = sprintf('<strong>Fatal error</strong>: Uncaught exception <strong>%s</strong> with message <strong>%s</strong> thrown in <strong>%s</strong> on line <strong>%s</strong>', get_class($e), $e->getMessage(), str_replace(TL_ROOT . '/', '', $e->getFile()), $e->getLine()); $strMessage .= "\n" . '<pre style="margin:11px 0 0">' . "\n" . str_replace(TL_ROOT . '/', '', $e->getTraceAsString()) . "\n" . '</pre>'; echo '<br>' . $strMessage; } show_help_message(); exit; }
public static function shutDown() { // restore TYPOlight handlers for exceptions and errors and hide them. // NOTE: this explicitly hides an Exception originating from the database class, // which want's to close resources in it's destructor that are already closed. // TEMPFIX: disabled this here, as it crashes in php as module sometimes... have no clue why. //set_error_handler('__error'); set_exception_handler('__exception'); ini_set('display_errors', false); self::shutDownArrayHandlers(); //self::$fb->setProcessorUrl(Environment::getInstance()->base . 'system/modules/debug/html/RequestProcessor.js'); //$this->setRendererUrl($URL); if ($error = error_get_last()) { switch ($error['type']) { case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: // we definately want to prevent the error message from being sent to the browser. if (self::$ob_started) { ob_end_clean(); ob_start(); } self::error(self::$severity[$error['type']] . ' ' . $error['message'] . ' in file: ' . $error['file'] . ' on line ' . $error['line'] . ' (discovered on shutdown, no trace available)'); self::error('active modules: ' . implode(', ', Config::getInstance()->getActiveModules())); show_help_message(); break; default: } } try { if (function_exists('getrusage')) { $dat = getrusage(); $executiontime = ($dat['ru_utime.tv_sec'] * 1000000.0 + $dat['ru_utime.tv_usec']) / 1000000.0 . ' seconds'; } else { $executiontime = 'N/A'; } self::$fb->info('TYPOlight debugger exiting. Max. mem used: ' . memory_get_peak_usage() . ' bytes. Execution time: ' . $executiontime); self::$fb->info('Supressed: ' . self::implodeWithKey(', ', array('Notices' => self::$supressed[E_NOTICE] + self::$supressed[E_USER_NOTICE], 'Warnings' => self::$supressed[E_WARNING] + self::$supressed[E_USER_WARNING]))); self::$fb->info('Executed: ' . self::$ticks . ' PHP statements.'); } catch (Exception $e) { // we can not log via headers anymore, echo the exception out then. echo 'Out of context Exception catched: ' . $e->getMessage(); } if (self::$ob_started) { ob_end_flush(); } }