Set the error handler to throw \ErrorExceptions (excluding deprecated warnings).

To revert call {@see restore_error_handler}.

@return callable|null the previous handler
964013
public static function set(): ?callable
    {
        if (! static::$handler) {
            static::$handler = function ($severity, $message, $file, $line): void {
                throw new \ErrorException($message, 0, $severity, $file, $line);
            };
        }

        return set_error_handler(static::$handler, E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
    }
313888
public function addRecoverableErrorHandler($handler) {
        if ( ! $handler instanceof INativeErrorHandler && ! is_callable($handler)) {
            throw new InvalidHandlerType(
                s('Recoverable error handler must be a callable or an instance of %s.',
                    INativeErrorHandler::class)
            );
        }

        if (is_callable($handler)) {
            $handler = $this->createNativeErrorHandler($handler);
        }

        $this->recoverableErrorHandlers[] = $handler;
    }
1153196
public function AllErrorToException(){

        if(!class_exists('\\Middlewares\\Whoops'))
            return ;

        set_error_handler(function($severity, $message, $file, $line){
            if (!(error_reporting() & $severity)) {
                // This error code is not included in error_reporting
                return;
            }
            throw new \ErrorException($message, 0, $severity, $file, $line);
        });
    }
1366657
protected function normalizeErrorHandler(callable $errorHandler)
    {
        if ($errorHandler instanceof ErrorHandler) {
            return $errorHandler;
        }

        $legacyResponseGenerator = function (
            $e,
            ServerRequestInterface $request,
            ResponseInterface $response
        ) use ($errorHandler) {
            return $errorHandler($request, $response, $e);
        };

        $errorHandler = new ErrorHandler(new Response(), $legacyResponseGenerator);
        return $errorHandler;
    }
106216
public function getError() : ?string 
    {
        if ( ! $this->hasError()) {
            $this->setError($this->getDefaultError());
        }
        return $this->error;
    }
375681
public static function httpErrors()
    {
        return function (callable $handler) {
            return function ($request, array $options) use ($handler) {
                if (empty($options['http_errors'])) {
                    return $handler($request, $options);
                }
                return $handler($request, $options)->then(
                    function (ResponseInterface $response) use ($request) {
                        $code = $response->getStatusCode();
                        if ($code < 400) {
                            return $response;
                        }
                        throw RequestException::create($request, $response);
                    }
                );
            };
        };
    }
1017883
public function shutdownHandler()
    {
        // Get last error
        if (null === $lastError = error_get_last()) {
            return;
        }

        if ($this->shouldCaptureFatalError($lastError['type'], $lastError['message'])) {
            $exception = new ErrorException(
                @$lastError['message'], 0, @$lastError['type'],
                @$lastError['file'], @$lastError['line']
            );

            $this->exceptionHandler($exception);
        }
    }
1000972
public function invoke()
    {
        $args      = func_get_args();
        $retries   = 0;
        $exception = null;
        $return    = null;

        /** @noinspection PhpUnusedLocalVariableInspection */
        $sc = SmartCallable::factory("restore_error_handler");
        set_error_handler(function($type, $message, $file, $line) {
                throw PHPException::factory(
                    $message,
                    $type,
                    $file,
                    $line
                );
            });

        do {
            try {
                $exception = null;
                $return    = call_user_func_array($this->callback, $args);
            } catch (Exception $exception) {
                $this->logger->error($exception->getMessage());
            }
            $action = $this->matchesCondition($return, $exception);
            if ("retry" == $action) {
                $retries++;
            }
        } while("retry" == $action && ($retries < $this->max_retries || -1 === $this->max_retries));
        
        if ($exception && "return" !== $action) {
            throw $exception;
        }
        if ($this->filter) {
            $return = call_user_func($this->filter, $return);
        }
        
        return $return;
    }
546502
public function invoke()
    {
        set_error_handler(function ($code, $message, $file, $line) {
            throw new \ErrorException($message, 0, $code, $file, $line);
        }, $this->errorReportingLevel === null ? error_reporting() : $this->errorReportingLevel
        );

        try {
            $returnValue = call_user_func($this->target);
        } catch (\Exception $e) {
            restore_error_handler();
            throw $e;
        }

        restore_error_handler();

        return $returnValue;
    }
696983
protected function initExceptionHandler()
    {
        if (!isset($this->chainedExceptionHandler)) {
            $this->chainedExceptionHandler = $this->setExceptionHandler([$this, 'handleException']) ?: false;
        }
    }
1065674
private function createErrorHandler()
    {
        /**
         * @param int $errno
         * @param string $errstr
         * @param string $errfile
         * @param int $errline
         * @return void
         * @throws \ErrorException if error is not within the error_reporting mask.
         */
        return function ($errno, $errstr, $errfile, $errline) {
            if (! (error_reporting() & $errno)) {
                // error_reporting does not include this error
                return;
            }

            throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
        };
    }
1252237
private function registerExceptionHandler()
    {
        $handler = $this->app[ExceptionHandlerContract::class];

        $this->singleton(ExceptionHandlerContract::class, function ($app) use ($handler) {
            return new Exceptions\Handler($app[Contracts\Tracker::class], $handler);
        });
    }
393136
public function getError()
    {
        if (count($this->errors) > 1) {
            trigger_error("There are multiple errors, returning only the first", E_USER_NOTICE);
        }
        
        return reset($this->errors) ?: null;
    }
883309
final public static function fromLastError()
    {
        $error = error_get_last();
        if ($error !== null) {
            return new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']);
        }
    }
344058
public function enableFatalErrorHandling() {
        if ($this->isFatalErrorHandlingEnabled()) {
            return;
        }

        register_shutdown_function(function () {
            return $this->errorConverter
                ->extractFatalErrorAndCallHandler($this);
        });
        $this->isFatalErrorHandlingEnabled = true;
    }
727656
public static function handleFatalError(array $error = null)
    {
        if (null === self::$reservedMemory) {
            return;
        }

        $handler = self::$reservedMemory = null;
        $handlers = [];
        $previousHandler = null;
        $sameHandlerLimit = 10;

        while (!\is_array($handler) || !$handler[0] instanceof self) {
            $handler = set_exception_handler('var_dump');
            restore_exception_handler();

            if (!$handler) {
                break;
            }
            restore_exception_handler();

            if ($handler !== $previousHandler) {
                array_unshift($handlers, $handler);
                $previousHandler = $handler;
            } elseif (0 === --$sameHandlerLimit) {
                $handler = null;
                break;
            }
        }
        foreach ($handlers as $h) {
            set_exception_handler($h);
        }
        if (!$handler) {
            return;
        }
        if ($handler !== $h) {
            $handler[0]->setExceptionHandler($h);
        }
        $handler = $handler[0];
        $handlers = [];

        if ($exit = null === $error) {
            $error = error_get_last();
        }

        if ($error && $error['type'] &= E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR) {
            // Let's not throw anymore but keep logging
            $handler->throwAt(0, true);
            $trace = isset($error['backtrace']) ? $error['backtrace'] : null;

            if (0 === strpos($error['message'], 'Allowed memory') || 0 === strpos($error['message'], 'Out of memory')) {
                $exception = new OutOfMemoryException($handler->levels[$error['type']].': '.$error['message'], 0, $error['type'], $error['file'], $error['line'], 2, false, $trace);
            } else {
                $exception = new FatalErrorException($handler->levels[$error['type']].': '.$error['message'], 0, $error['type'], $error['file'], $error['line'], 2, true, $trace);
            }
        } else {
            $exception = null;
        }

        try {
            if (null !== $exception) {
                self::$exitCode = 255;
                $handler->handleException($exception, $error);
            }
        } catch (FatalErrorException $e) {
            // Ignore this re-throw
        }

        if ($exit && self::$exitCode) {
            $exitCode = self::$exitCode;
            register_shutdown_function('register_shutdown_function', function () use ($exitCode) { exit($exitCode); });
        }
    }
940917
final public function handler($type = 'error', $action = 'restore', $callable_handler = false, $error_types = null)
    {
        if (empty($error_types)) {
            $error_types = E_ALL | E_STRICT;
        }
        switch (strtolower($type)) {
            case 'error':
                switch (strtolower($action)) {
                    case 'restore':
                        return restore_error_handler();
                        break;
                    case 'set':
                        return set_error_handler($callable_handler, $error_types);
                        break;
                    default:
                        return false;
                }
                break;
            case 'exception':
                switch (strtolower($action)) {
                    case 'restore':
                        return restore_exception_handler();
                        break;
                    case 'set':
                        return set_exception_handler($callable_handler);
                        break;
                    default:
                        return false;
                }
                break;
            default:
                return false;
        }
    }