/** * Report an exception to the user * @param Exception|Throwable $e */ protected static function report($e) { try { // Try and show the exception prettily, with the normal skin infrastructure if ($e instanceof MWException) { // Delegate to MWException until all subclasses are handled by // MWExceptionRenderer and MWException::report() has been // removed. $e->report(); } else { MWExceptionRenderer::output($e, MWExceptionRenderer::AS_PRETTY); } } catch (Exception $e2) { // Exception occurred from within exception handler // Show a simpler message for the original exception, // don't try to invoke report() MWExceptionRenderer::output($e, MWExceptionRenderer::AS_RAW, $e2); } }
/** * Run the current MediaWiki instance; index.php just calls this */ public function run() { try { $this->setDBProfilingAgent(); try { $this->main(); } catch (ErrorPageError $e) { // Bug 62091: while exceptions are convenient to bubble up GUI errors, // they are not internal application faults. As with normal requests, this // should commit, print the output, do deferred updates, jobs, and profiling. $this->doPreOutputCommit(); $e->report(); // display the GUI error } } catch (Exception $e) { $context = $this->context; $action = $context->getRequest()->getVal('action', 'view'); if ($e instanceof DBConnectionError && $context->hasTitle() && $context->getTitle()->canExist() && in_array($action, ['view', 'history'], true) && HTMLFileCache::useFileCache($this->context, HTMLFileCache::MODE_OUTAGE)) { // Try to use any (even stale) file during outages... $cache = new HTMLFileCache($context->getTitle(), 'view'); if ($cache->isCached()) { $cache->loadFromFileCache($context, HTMLFileCache::MODE_OUTAGE); print MWExceptionRenderer::getHTML($e); exit; } } MWExceptionHandler::handleException($e); } $this->doPostOutputShutdown('normal'); }
/** * Run hook to allow extensions to modify the text of the exception * * @param string $name Class name of the exception * @param array $args Arguments to pass to the callback functions * @return string|null String to output or null if any hook has been called */ public function runHooks($name, $args = []) { return MWExceptionRenderer::runHooks($this, $name, $args); }