Handle a throwable, and return whether it was handled and the remaining stack should be aborted.

@param Exception|Throwable|mixed $throwable

@return bool
436822
public function handle($throwable)
    {
        if ($throwable instanceof Exception) {
            $response = $this->handler->handleException($this->defaultRequest, $this->defaultResponse, $throwable);
        } elseif ($throwable instanceof Throwable) {
            $response = $this->handler->handleThrowable($this->defaultRequest, $this->defaultResponse, $throwable);
        } else {
            return false;
        }

        if ($response instanceof ResponseInterface) {
            $this->renderResponse($response);
            return true;
        } else {
            return false;
        }
    }
945758
protected function error(\Throwable $exception)
    {
        if ($this->errorHandler === null) {
            throw $exception;
        }

        ($this->errorHandler)($exception);
    }
1371386
protected function shouldExceptionBeLogged(Throwable $exception): bool
	{
		if($this->logger === null)
		{
			return false;
		}

		foreach($this->disableLoggingFor as $exceptionType)
		{
			if($exception instanceof $exceptionType)
			{
				return false;
			}
		}

		return true;
	}
741447
public function handleException( \Throwable $e ) : bool
    {
        // Render exception
        $output = $this->renderer->output( $e );
        
        // output
        $this->logger->error($output, [
            'exception' => $e,
        ]);
    
        return true;
    }
31983
public function exceptionHandler($exception)
    {
        $this->lastHandledException = $exception;

        $this->client->catchException($exception);

        if ($this->oldExceptionHandler) {
            call_user_func(
                $this->oldExceptionHandler,
                $exception
            );
        }
    }
1006120
final public static function getBaseException(Throwable $throwable) : Throwable
    {
        while ($throwable->getPrevious() !== null) {
            $throwable = $throwable->getPrevious();
        }

        return $throwable;
    }
810995
public function handleException( Exception $exception )
    {
        // restore previous exception handler
        restore_exception_handler();

        if ( $exception instanceof Exception )
        {
            $error = [
                'file'    => $exception->getFile(),
                'line'    => $exception->getLine(),
                'message' => $exception->getMessage(),
                'trace'   => $this->getBacktrace( $exception->getTrace() ),
            ];
        }
        else
        {
            return;
        }

        if ( NULL !== $this->exceptionCallback )
        {
            call_user_func_array( $this->exceptionCallback, $error );
        }

        return TRUE;
    }
339521
protected function handleException($passable, Exception $e)
    {
        if (! $this->container->bound(ExceptionHandler::class) ||
            ! $passable instanceof Request) {
            throw $e;
        }

        $handler = $this->container->make(ExceptionHandler::class);

        $handler->report($e);

        $response = $handler->render($passable, $e);

        if (method_exists($response, 'withException')) {
            $response->withException($e);
        }

        return $response;
    }
341274
protected function handleException($passable, Exception $e)
    {
        $handler = $this->container->make(ExceptionHandler::class);

        $handler->report($e);

        return $this->createExceptionResult($e);
    }
54795
public function handle(Throwable $exception) : void
    {
        foreach ($this->handlers as $handler) {
            $result = $handler($exception);

            if ($result instanceof Throwable) {
                $exception = $result;
            }
        }

        throw $exception;
    }
669507
public static function exceptionHandler(\Throwable $throwable)
    {
        self::showError($throwable);

        Log::error((string)$throwable);
    }
935895
protected function fail(\Throwable $error): void
    {
        if (~$this->state & AbstractPromise::PENDING) {
            return;
        }
        
        $callbacks = $this->result;
        
        $this->state ^= AbstractPromise::PENDING | AbstractPromise::FAILED;
        $this->result = $error;
        
        if ($this instanceof Cancellable) {
            $this->context->unregisterCancellation($this);
        }
        
        if ($callbacks) {
            if (\is_array($callbacks)) {
                foreach ($callbacks as $callback) {
                    try {
                        $callback($error);
                    } catch (\Throwable $e) {
                        $this->context->handleError($e);
                    }
                }
            } else {
                try {
                    $callbacks($error);
                } catch (\Throwable $e) {
                    $this->context->handleError($e);
                }
            }
        }
    }
1178487
function onFailure(/*callable*/$callable)
    {
        if ($callable === false)
        {
            // Disable On Failure Handler
            //
            $this->_onFailure = $callable;
            return $this;
        }


        if (! is_callable($callable) )
            throw new \Exception(sprintf(
                'The argument given is not callable; given: (%s).'
                , \Poirot\Std\flatten($callable)
            ));


        ## bind it into latest bind object
        #
        // DO_LEAST_PHPVER_SUPPORT 5.4 closure bindto
        if ($callable instanceof \Closure && version_compare(phpversion(), '5.4.0') > 0) {
            $callable = \Closure::bind(
                $callable
                , $this
                , get_class($this)
            );
        }

        $this->_onFailure = $callable;
        return $this;
    }
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;
    }
117432
public function handleException($exception)
    {
        // Walk the registered handlers in the reverse order
        // they were registered, and pass off the exception
        $inspector = $this->getInspector($exception);

        // Capture output produced while handling the exception,
        // we might want to send it straight away to the client,
        // or return it silently.
        ob_start();

        // Just in case there are no handlers:
        $handlerResponse = null;

        foreach (array_reverse($this->handlerStack) as $handler) {
            $handler->setRun($this);
            $handler->setInspector($inspector);
            $handler->setException($exception);

            // The HandlerInterface does not require an Exception passed to handle()
            // and neither of our bundled handlers use it.
            // However, 3rd party handlers may have already relied on this parameter,
            // and removing it would be possibly breaking for users.
            $handlerResponse = $handler->handle($exception);

            if (in_array($handlerResponse, array(Handler::LAST_HANDLER, Handler::QUIT))) {
                // The Handler has handled the exception in some way, and
                // wishes to quit execution (Handler::QUIT), or skip any
                // other handlers (Handler::LAST_HANDLER). If $this->allowQuit
                // is false, Handler::QUIT behaves like Handler::LAST_HANDLER
                break;
            }
        }

        $willQuit = $handlerResponse == Handler::QUIT && $this->allowQuit();

        $output = ob_get_clean();

        // If we're allowed to, send output generated by handlers directly
        // to the output, otherwise, and if the script doesn't quit, return
        // it so that it may be used by the caller
        if ($this->writeToOutput()) {
            // @todo Might be able to clean this up a bit better
            // If we're going to quit execution, cleanup all other output
            // buffers before sending our own output:
            if ($willQuit) {
                while (ob_get_level() > 0) {
                    ob_end_clean();
                }
            }

            $this->writeToOutputNow($output);
        }

        if ($willQuit) {
            flush(); // HHVM fix for https://github.com/facebook/hhvm/issues/4055
            exit(1);
        }

        return $output;
    }
758303
public function handleException($exception)
    {
        #$this->system->startOutputBuffering();
        #$willQuit = $handlerResponse == Handler::QUIT && $this->allowQuit();
        #$output = $this->system->cleanOutputBuffer();
        /*
        if ($this->writeToOutput()) {
            if ($willQuit) {
                while ($this->system->getOutputBufferLevel() > 0) {
                    $this->system->endOutputBuffering();
                }
                if (Misc::canSendHeaders() && $handlerContentType) {
                    header("Content-Type: {$handlerContentType}");
                }
            }
            $this->writeToOutputNow($output);
        }
        if ($willQuit) {
            $this->system->flushOutputBuffer();
            $this->system->stopExecution(1);
        }
        */
        $log = $exception->getMessage() . "\n" . $exception->getTraceAsString() . LINEBREAK;
        if ( ini_get('log_errors') ) {
            error_log($log, 0);
        }
        $output = get_class($exception).":".$log;
        //return $output;
        if(method_exists($exception, 'getSeverity')) {
            $severityCode = $exception->getSeverity();
            switch($severityCode) {
			case E_ERROR: // 1 //
				$severity = 'E_ERROR';
				break;
			case E_WARNING: // 2 //
				$severity = 'E_WARNING';
				break;
			case E_PARSE: // 4 //
				$severity = 'E_PARSE';
				break;
			case E_NOTICE: // 8 //
				$severity = 'E_NOTICE';
				break;
			case E_CORE_ERROR: // 16 //
				$severity = 'E_CORE_ERROR';
				break;
			case E_CORE_WARNING: // 32 //
				$severity = 'E_CORE_WARNING';
				break;
			case E_COMPILE_ERROR: // 64 //
				$severity = 'E_COMPILE_ERROR';
				break;
			case E_COMPILE_WARNING: // 128 //
				$severity = 'E_COMPILE_WARNING';
				break;
			case E_USER_ERROR: // 256 //
				$severity = 'E_USER_ERROR';
				break;
			case E_USER_WARNING: // 512 //
				$severity = 'E_USER_WARNING';
				break;
			case E_USER_NOTICE: // 1024 //
				$severity = 'E_USER_NOTICE';
				break;
			case E_STRICT: // 2048 //
				$severity = 'E_STRICT';
				break;
			case E_RECOVERABLE_ERROR: // 4096 //
				$severity = 'E_RECOVERABLE_ERROR';
				break;
			case E_DEPRECATED: // 8192 //
				$severity = 'E_DEPRECATED';
				break;
			case E_USER_DEPRECATED: // 16384 //
				$severity = 'E_USER_DEPRECATED';
				break;
			case E_ALL: // 32767 //
				$severity = 'E_ALL';
				break;
			default:
				$severity = 'UNKOWN';
				break;
		}
        }
    	if ( env('APP_DEBUG') === true ) {
        	print '
				<!DOCTYPE html>
				<html lang="en">
					<head>
						<meta charset="utf-8">
						<meta http-equiv="X-UA-Compatible" content="IE=edge">
						<meta name="viewport" content="width=device-width, initial-scale=1">
						<title>Error</title>
						<!-- Fonts -->
						<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">
						<style>html, body {background-color: #fff;color: #636b6f;font-family: \'Nunito\', sans-serif;font-weight: 100;height: 100vh;margin: 0;}.full-height {height: 90vh;}.flex-center {align-items: center;display: flex;justify-content: center;}.content {text-align: center;}.title {font-size: 36px;padding: 20px;}</style>
					</head>
					<body>
						<div class="flex-center position-ref full-height">
							<div class="content">
								<h2 class="title" style="color: rgb(190, 50, 50)">Exception Occured</h2>
        						<table style="width: 800px; display: inline-block;text-align:left">
        							<tr style="background-color:rgb(230,230,230)">
										<th style="width: 80px">Type</th>
										<td>'. get_class($exception) .'</td>
									</tr>
        							<tr style="background-color:rgb(240,240,240)">
										<th>Code</th>
										<td>'. $exception->getCode() .'</td>
									</tr>
        							<tr style="background-color:rgb(240,240,240)">
										<th>Trace</th>
										<td>'. trim(str_replace('#', '<br>#', $exception->getTraceAsString()),'<br>') .'</td>
									</tr>'. 
                                        (isset($severityCode) ? '
        							<tr style="background-color:rgb(240,240,240)">
										<th>Severity</th>
										<td>'.  $severityCode .' - '.$severity.'</td>
									</tr>.'
                                          : '').'
        							<tr style="background-color:rgb(240,240,240)">
										<th>Message</th>
										<td>'. $exception->getMessage() .'</td>
									</tr>
        							<tr style="background-color:rgb(230,230,230)">
										<th>File</th>
										<td>'. $exception->getFile() .'</td>
									</tr>
        							<tr style="background-color:rgb(240,240,240)">
										<th>Line</th>
										<td>'. $exception->getLine() .'</td>
									</tr>
        						</table>
							</div>
						</div>
					</body>
				</html>
			';
    	}
    	else {
        	$message = "Type: " . get_class($exception) . "; Message: {$exception->getMessage()}; File: {$exception->getFile()}; Line: {$exception->getLine()};";
        	if(!file_exists(LOGS . "/debug.log") || !is_file(LOGS . "/debug.log")) {
				file_put_contents( LOGS . "/debug.log", '');
			}
        	error_log("[".date('Y-y-d H:i:s')."] " . $message . PHP_EOL . PHP_EOL, 3, LOGS . "/debug.log");
			//header( "Location: {$config["error_page"]}" );
			echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Error</title><!-- Fonts --><link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">
<style>html, body {background-color: #fff;color: #636b6f;font-family: \'Nunito\', sans-serif;font-weight: 100;height: 100vh;margin: 0;}.full-height {height: 90vh;}.flex-center {align-items: center;display: flex;justify-content: center;}.content {text-align: center;}.title {font-size: 36px;padding: 20px;}</style><body><div class="flex-center position-ref full-height"><div class="content"><div class="title">It looks like something went wrong.</div></div></div></body></html>';
    	}
    	exit();
    }
689908
public function willThrowException(\Throwable $exception): self
    {
        if ($this->hasReturnSelf) {
            throw new \InvalidArgumentException(sprintf('%s: There is already a return self', __METHOD__));
        }

        if ($this->hasReturn) {
            throw new \InvalidArgumentException(sprintf('%s: There is already a return', __METHOD__));
        }

        if ($this->hasReturnCallback) {
            throw new \InvalidArgumentException(sprintf('%s: There is already a return callback', __METHOD__));
        }

        $this->exception = $exception;

        return $this;
    }