Handle an exception

@param $exception (can be \Throwable or \Exception)
@return string $output Output generated by the configured handlers
434973
public function handle_exception($exception) {
		$quit = false;
		$output = '';

		foreach ($this->handlers as $handler) {
			if ($handler->can_run()) {
				$handler->set_exception($exception);

				// The output is a concatenation of all output returned by the
				// handlers. Ideally, we only have one handler sending output.
				$output .= $handler->handle();

				if ($handler->requests_quit() === true) {
					$quit = $handler->requests_quit();
				}

				// If the handler claims it should be the last handler, break out of the loop
				if ($handler->is_last() === true) {
					break;
				}
			}
		}

		if (trim($output) !== '') {
			echo $output;
		}

		if ($quit === true) {
			// Since we are exiting after an error, don't exit with 0
			exit(1);
		}
	}
647957
public function handleException($exception)
    {
    	if ($exception instanceof ExitException) {
    		return;
    	}
    	
    	$this->exception = $exception;
    	
    	// disable error capturing to avoid recursive errors while handling exceptions
    	$this->unregister();
    	
    	try {
    		// 记录日志
    		$this->logException($exception);
    		
    		if ($this->options['discard_output']) {
    			$this->clearOutput();
    		}
    		
    		// 显示错误信息
    		$this->renderException($exception);
    		
    	} catch (\Exception $e) {
    		// an other exception could be thrown while displaying the exception
    		$msg = (string) $e;
    		$msg .= "\nPrevious exception:\n";
    		$msg .= (string) $exception;
    		$msg .= "\n\$_SERVER = " . var_export($_SERVER, true);
    		
    		error_log($msg);
    		exit(1);
    	}
    	
    	$this->exception = null;
    }
385355
protected function throwError($exception)
    {
        switch ($exception->getResponse()->getStatusCode()) {
            case 400:
                throw new BadRequestException($exception);
                break;

            case 401:
                throw new UnauthorizedException($exception);
                break;

            case 403:
                throw new MethodNotAllowedException($exception);
                break;

            case 404:
                throw new NotFoundException($exception);
                break;

            default:
                throw new Exception($exception);
                break;
        }
    }
279615
public function exceptionHandler(\Throwable $exception)
    {
        \BFW\Application::getInstance()
            ->getMonolog()
            ->getLogger()
            ->debug(
                'New exception catched.',
                [
                    'msg'  => $exception->getMessage(),
                    'file' => $exception->getFile(),
                    'line' => $exception->getLine()
                ]
            );
        
        $errorRender = $this->obtainExceptionRender();
        
        $this->callRender(
            $errorRender,
            'Exception Uncaught', 
            $exception->getMessage(), 
            $exception->getFile(), 
            $exception->getLine(), 
            $exception->getTrace(),
            $exception->getCode()
        );
    }
610869
public function handle($exception)
    {
        $exception = call_user_func($this->config('exceptionCallback'), $exception);
        if (!$exception) {
            return;
        }
        $client = $this->client();
        $client = call_user_func($this->config('clientCallback'), $client);
        if ($client) {
            $client->captureException($exception);
        }
    }
71172
public function handle($exception) {
        $message = $exception->getMessage();

        // Add the exception backtrace for developers.
        if (debugging('', DEBUG_DEVELOPER)) {
            $message .= "\n".format_backtrace(get_exception_info($exception)->backtrace, true);
        }

        // Switch to response.
        $type = str_replace('Request', 'Response', $this->type);

        // Build the appropriate xml.
        $response = lti_get_response_xml('failure', $message, $this->id, $type);

        $xml = $response->asXML();

        // Log the request if necessary.
        if ($this->log) {
            lti_log_response($xml, $exception);
        }

        echo $xml;
    }
448188
public function handleException($exception)
    {
        $this->setExceptionHandler(null);
        $this->setErrorHandler(null);
        
        $isInstanceOf = array_map(function ($class) use ($exception) {
            return is_a($exception, $class);
        }, $this->logExceptionClasses);
        
        if ($exception instanceof \Error || $exception instanceof \ErrorException) {
            $type = $exception instanceof \Error ? $exception->getCode() : $exception->getSeverity();
            $shouldLog = $this->getLoggedErrorTypes() & $type;
        } else {
            $shouldLog = array_sum($isInstanceOf) > 0;
        }
        
        if ($shouldLog) {
            $this->log($exception);
        }
        
        $this->callOnFatalError($exception);
        
        if ($this->chainedExceptionHandler) {
            call_user_func($this->chainedExceptionHandler, $exception);
        }
        
        throw $exception; // This is now handled by the default exception and error handler
    }
404789
protected function handleException($handler, Throwable $exception)
	{
		if($handler instanceof Closure)
		{
			return $handler($exception);
		}

		return $this->handlerFactory($handler)->handle($exception);
	}
848482
public function handle($exception)
    {
        $exception = call_user_func($this->config('exceptionCallback'), $exception);
        if (!$exception) {
            return;
        }
        if (!extension_loaded('atatus')) {
            return;
        }
        $apiKey = $this->config('apiKey');
        if (!empty($apiKey)) {
            atatus_set_api_key($apiKey);
        }
        atatus_notify_exception($exception);
    }
294126
public function handleException($exception)
    {
        //Log the error
        Injector::inst()->get(LoggerInterface::class)->debug($exception->getMessage());
        $request = Injector::inst()->get(HTTPRequest::class);
        $request->getSession()->set('notice', true);
        $request->getSession()->set('noticeType', 'bad');
        $message = $exception->getMessage();
        if ($exception->hasResponse()) {
            $response = json_decode($exception->getResponse()->getBody(), true);
            if (isset($response['error']) && isset($response['error']['message'])) {
                $message = $response['error']['message'];
            }
        }
        $request->getSession()->set('noticeText', $message);
    }
584665
public function exceptionHandler($exception) {
		try {
			// load errorhandler
			$debug = Factory::load('Debug');
			$debug->errorhandler($exception);
		} catch (\Exception $e) {
			echo "<pre>$exception</pre>\n\n";

			// useful if the \Exception handler itself contains errors
			echo "<pre>The Debug class threw an exception:\n$e</pre>";
		}
	}
1099496
public function handleException($exception)
    {
        if ($exception instanceof ExitException) {
            return;
        }

        $this->exception = $exception;

        // disable error capturing to avoid recursive errors while handling exceptions
        $this->unregister();

        // set preventive HTTP status code to 500 in case error handling somehow fails and headers are sent
        // HTTP exceptions will override this value in renderException()
        if (PHP_SAPI !== 'cli') {
            http_response_code(500);
        }

        try {
            $this->logException($exception);
            if ($this->discardExistingOutput) {
                $this->clearOutput();
            }
            $this->renderException($exception);
            if (!Zilf_ENV_TEST) {
                \Zilf::getLogger()->flush(true);
                if (defined('HHVM_VERSION')) {
                    flush();
                }
                exit(1);
            }
        } catch (\Exception $e) {
            // an other exception could be thrown while displaying the exception
            $this->handleFallbackExceptionMessage($e, $exception);
        } catch (\Throwable $e) {
            // additional check for \Throwable introduced in PHP 7
            $this->handleFallbackExceptionMessage($e, $exception);
        }

        $this->exception = null;
    }
156968
public function handleException($exception)
    {
        $inspector = $this->getInspector($exception);

        $handlerResponse    = null;
        $handlerContentType = null;
        $this->system->startOutputBuffering();

        // 如果当前没有Response 即不能输出到浏览器的情况 强制应用PlainTextHandler
        if (!$this->system->ResIns()) {
            $this->clearHandlers();
            $this->pushHandler(new PlainTextHandler);
        }

        //  AJAX自动返回Json
        if (Misc::isAjaxRequest() && $this->options['auto_conversion']) {
            $this->pushHandler(new JsonResponseHandler);
        }

        // 关闭详细错误输出
        if (!$this->options['detailed']) {
            $this->clearHandlers();
            $handlerContentType = 'text/html;charset=utf-8';
            echo $this->options['information'];
        }

        // 反向的遍历handles进行输出设置
        foreach (array_reverse($this->handlerStack) as $handler) {
            /* @var HandlerInterface|PrettyPageHandler $handler */
            if ($handler instanceof PrettyPageHandler) {
                $handler->handleUnconditionally(true);
            }

            $handler->setRun($this);
            $handler->setInspector($inspector);
            $handler->setException($exception);
            $handlerResponse    = $handler->handle($exception);
            $handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null;

            if (in_array($handlerResponse, [Handler::LAST_HANDLER, Handler::QUIT])) {
                break;
            }
        }

        $output = $this->system->cleanOutputBuffer();
        $this->writeToOutputNow($output, $handlerContentType);
    }
179186
public function handleException($exception)
    {
        if ($exception instanceof ExitException) {
            return;
        }

        $this->exception = $exception;

        // disable error capturing to avoid recursive errors while handling exceptions
        $this->unregister();

        // set preventive HTTP status code to 500 in case error handling somehow fails and headers are sent
        // HTTP exceptions will override this value in renderException()
        if (PHP_SAPI !== 'cli') {
            http_response_code(500);
        }

        try {
            $this->logException($exception);
            if ($this->discardExistingOutput) {
                $this->clearOutput();
            }
            $this->renderException($exception);
            if (!YII_ENV_TEST) {
                \Yii::getLogger()->flush(true);
                if (defined('HHVM_VERSION')) {
                    flush();
                }
                exit(1);
            }
        } catch (\Exception $e) {
            // an other exception could be thrown while displaying the exception
            $msg = "An Error occurred while handling another error:\n";
            $msg .= (string) $e;
            $msg .= "\nPrevious exception:\n";
            $msg .= (string) $exception;
            if (YII_DEBUG) {
                if (PHP_SAPI === 'cli') {
                    echo $msg . "\n";
                } else {
                    echo '<pre>' . htmlspecialchars($msg, ENT_QUOTES, Yii::$app->charset) . '</pre>';
                }
            } else {
                echo 'An internal server error occurred.';
            }
            $msg .= "\n\$_SERVER = " . VarDumper::export($_SERVER);
            error_log($msg);
            if (defined('HHVM_VERSION')) {
                flush();
            }
            exit(1);
        }

        $this->exception = null;
    }
732832
public static function handleException($exception)
    {
        static::handleError($exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception, true);
    }
1285722
public function PHPExceptionHandler($exception)
    {
        session_write_close();
        $message = $exception->getMessage() . ' | File: {file} | Ln: {line} | ST: {stacktrace}';
        $context = array(
            'file' => $exception->getFile(),
            'line' => $exception->getLine(),
            'stacktrace' => $exception->getTraceAsString()
        );
        $this->logger->log($this->exceptionLogLevel, $message, $context);
    }
983710
public function handleException($exception)
    {
        $isHandled = false;
        try {
            $isHandled = $this->handler->handle($exception);
        } catch (Exception $ex) {
        } catch (Throwable $ex) {
        }

        // Bomb out if handler returns true, since was able to render something to the client
        if ($isHandled) {
            exit;
        }

        // Rethrow to be handled by default php exception handling.
        throw $exception;
    }