Handle uncaught exceptions.

Iterates over the configured error handlers and invokes them in order

@param Throwable|Exception $exception A Throwable or Exception instance
@return void
@see http://php.net/manual/en/function.set-exception-handler.php
179575
public function handle($exception)
    {
        $handlers = (array)$this->config('handlers');
        foreach ($handlers as $handler => $config) {
            $handlerClass = $handler;
            if (!class_exists($handlerClass)) {
                $handlerClass = 'Josegonzalez\ErrorHandlers\Handler\\' . $handler;
            }
            if (!class_exists($handlerClass)) {
                $handlerClass = 'Josegonzalez\ErrorHandlers\Handler\\' . $handler . 'Handler';
            }
            if (!class_exists($handlerClass)) {
                continue;
            }
            $instance = new $handlerClass((array)$config);
            $instance->handle($exception);
        }

        return false;
    }
1036117
public function handleException($exception)
    {
        if (! $exception instanceof Exception) {
            $exception = new FatalThrowableError($exception);
        }

        $this->getExceptionHandler()->report($exception);

        if ($this->app->runningInConsole()) {
            $this->renderForConsole($exception);
        } else {
            $this->renderHttpResponse($exception);
        }
    }
931581
public function handler(Throwable $exception): void
	{
		try
		{
			// Empty output buffers

			$this->clearOutputBuffers();

			// Loop through the exception handlers

			foreach($this->handlers as $handler)
			{
				if($exception instanceof $handler['exceptionType'])
				{
					if($this->handleException($handler['handler'], $exception) !== null)
					{
						break;
					}
				}
			}

			// Log exception

			if($this->shouldExceptionBeLogged($exception))
			{
				$this->getLogger()->error($exception->getMessage(), ['exception' => $exception]);
			}
		}
		catch(Throwable $e)
		{
			// Empty output buffers

			$this->clearOutputBuffers();

			// One of the exception handlers failed so we'll just show the user a generic error screen

			echo $e->getMessage() . ' on line [ ' . $e->getLine() . ' ] in [ ' . $e->getFile() . ' ]' . PHP_EOL;
		}

		exit(1);
	}
7201
public function exceptionHandler($exception)
  {
    # Set 500 error code as well as something unexpected happened
    $this->getResponse()->setStatusCode(500);

    # Log the exception
    $this->getLogger()->critical(
      $exception->getMessage().' in file '.$exception->getFile().' on line '.$exception->getLine(),
      $exception->getTrace()
    );

    # Output a response
    $this->getResponse()->send();
  }
1260024
public function exceptionHandler(Exception $exception)
    {
        $this->logger->addError($exception->getMessage(), array($exception->getFile(), $exception->getLine()));
        exit(-1);
    }
254226
public function handleException(Exception &$exception)
    {
        if($template = end($this->_stack))
        {
            if($this->_source == $exception->getFile())
            {
                //Prevents any partial templates from leaking.
                ob_get_clean();

                //Re-create the exception and set the real file path
                if($exception instanceof ErrorException)
                {
                    $class = get_class($exception);
                    $file  = $this->getObject('template.locator.factory')->locate($template) ?: $this->_source;

                    $exception = new KTemplateExceptionError(
                        $exception->getMessage(),
                        $exception->getCode(),
                        $exception->getSeverity(),
                        $file,
                        $exception->getLine(),
                        $exception
                    );
                }
            }
        }
    }
1235434
function onUncaughtException(\Throwable $exception): void
    {
        try {
            // handle the exception
            try {
                $this->emit(ErrorHandlerEvents::EXCEPTION, $exception, $this->debug);
            } catch (\Throwable $e) {
                $exception = new ChainedException(
                    'Additional exception was thrown from an [exception] event listener. See previous exceptions.',
                    0,
                    Exception::joinChains($exception, $e)
                );
            }

            $this->invokeErrorScreen($exception);

            return;
        } catch (\Throwable $e) {
            $exception = new ChainedException(
                sprintf('Additional exception was thrown while trying to invoke %s. See previous exceptions.', get_class($this->errorScreen)),
                0,
                Exception::joinChains($exception, $e)
            );

            $this->emit(ErrorHandlerEvents::FAILURE, $exception, $this->debug);
        }

        // unhandled exception
        if ($this->debug && $this->printUnhandledExceptionInDebug) {
            echo Exception::render($exception, true, true);
        }
    }
1037498
public function generic_exception_handler( $exception ) {
		// Paulus - Handle all of our "ApiException"s
		if ( $exception instanceOf ApiException ) {
			// Handle our ApiException interface exceptions from Paulus
			$this->api_exception_handler( $exception );
		}
		// All other exceptions
		else {
			// Log the error
			$this->error_log( $exception->getMessage() );

			// Let's handle the exception gracefully (RESTfully)
			$this->abort( 500, 'EXCEPTION_THROWN', $exception->getMessage() );
		}
	}
991973
public function handleException($exception)
	{
		if (is_object($this->logger) && !in_array($exception->getCode(), [403, 404]))
		{
			$this->logger->log(
				'error',
				$exception->getMessage(),
				array(
					'code' => $exception->getCode(),
					'file' => $exception->getFile(),
					'line' => $exception->getLine()
				)
			);
		}

		return $this->renderer->render($exception);
	}
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;
    }
627836
public function handleException($exception)
    {
        // Ignore if the error is suppressed by using the shut-up operator @
        if (error_reporting() === 0) {
            return;
        }

        $this->renderingOptions = $this->resolveCustomRenderingOptions($exception);

        if ($this->throwableStorage instanceof ThrowableStorageInterface && isset($this->renderingOptions['logException']) && $this->renderingOptions['logException']) {
            $message = $this->throwableStorage->logThrowable($exception);
            $this->logger->critical($message);
        }

        switch (PHP_SAPI) {
            case 'cli':
                $this->echoExceptionCli($exception);
                break;
            default:
                $this->echoExceptionWeb($exception);
        }
    }
89831
public function handle($exception)
    {
        $file = $exception->getFile();
        $line = $exception->getLine();
        $message = $exception->getMessage();
        $trace = $exception->getTrace();

        // Reverse and reset default order
        $trace = array_reverse($trace);

        // The name of thrown exception
        $class = get_class($exception);

        // Above variables will be available in the template
        require($this->templateFile);
    }
186956
public function handleException($exception)
  {
    // Disable error capturing to avoid recursive errors while handling exceptions.
    $this->unregister();

    try
    {
      $this->clearOutput();
      $this->renderException($exception);

      exit(-1);
    }
    catch (\Exception $e)
    {
      // Another exception could be thrown while displaying the exception.
      $message = "An Error occurred while handling another error:\n";
      $message .= (string)$e;
      $message .= "\nPrevious exception:\n";
      $message .= (string)$exception;
      if ($this->myDebug)
      {
        $this->echoMessage($message);
      }
      else
      {
        $this->echoMessage('An internal server error occurred.');
      }
      $message .= "\n\$_SERVER = ".print_r($_SERVER, true);
      error_log($message);

      exit(1);
    }
  }
1207570
protected function handleException(\Exception $exception)
    {
        $this->response->setStatus(500);
        // may be we want also an exceptionHandler e.g. to notify somebody, ...
        $this->addFlashMessage(
            $exception->getMessage(),
            get_class($exception),
            Message::SEVERITY_ERROR,
            [],
            $exception->getCode()
        );
    }
1118223
public function handle(Exception $exception)
    {
        try {

            $handlers = array_filter($this->handlers, function ($handler) use ($exception) {
                return $exception instanceof $handler[0];
            });

            foreach ($handlers as $handler) {
                $error = $handler[1]($exception);

                if ($error !== null) {
                    break;
                }
            }

        } catch (Exception $e) {

            echo sprintf('[%d] %s in %s', $e->getLine(), $e->getMessage(), $e->getFile());
        }
    }
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()
        );
    }
183013
private function logException(Exception $exception): void
    {
        if ($exception instanceof HttpExceptionInterface && $exception->getStatusCode() < 500) {
            return;
        }

        $this->logger->critical(
            sprintf(
                'Uncaught PHP Exception %s: "%s" at %s line %s',
                get_class($exception),
                $exception->getMessage(),
                $exception->getFile(),
                $exception->getLine()
            ),
            ['exception' => $exception]
        );
    }