Convert any type into an exception

@param $error
@return \Exception|string
8608
public function decorateException($error)
    {
        $application = $this->application;

        if (is_callable($error)) {
            $error = $application->getContainer()->call($error, [$application]);
        }

        if (is_object($error) && !($error instanceof \Exception)) {
            $error = method_exists($error,
                '__toString') ? $error->__toString() : 'Error with object ' . get_class($error);
        }

        if (is_resource($error)) {
            $error = 'Error with resource type ' . get_resource_type($error);
        }

        if (is_array($error)) {
            $error = implode("\n", $error);
        }

        if (!($error instanceof \Exception)) {
            $error = new \Exception(is_scalar($error) ? $error : 'Error with ' . gettype($error));
        }

        return $error;
    }
1021640
public static function createExceptionForError(IError $error) {
        $class = static::getExceptionClassForError($error->getCode());
        $ex = new $class(
            $error->getCode(),
            $error->getMessage(),
            $error->getFile(),
            $error->getLine()
        );

        return $ex;
    }
185616
public function exceptionFlash(\Exception $exception, $type = 'error')
    {
        if ($exception instanceof MbException) {
            $messages = $exception->getMessages();

            if (empty($messages)) {
                return $this->errorFlash($exception->getMessage(), $type);
            } else {
                $erros = [$exception->getMessage()];

                foreach ($messages as $item => $message) {
                    if (is_array($message)) {
                        foreach ($message as $erro) {
                            $erros[] = "<strong>{$item}</strong>: {$erro}";
                        }
                    } else {
                        $erros[] = $message;
                    }
                }

                return $this->errorFlash($erros, $type);
            }

        } else {
            return $this->errorFlash($exception->getMessage(), $type);
        }
    }
965996
private function getResponseErrorMessage($error)
    {
        $message = $error->message;

        if (isset($error->details) && is_array($error->details)) {
            foreach ($error->details as $detail) {
                $message .= implode(' - ', $detail->errors).' ['.$detail->error_type.' in '.$detail->parameter.'] ';
            }
        }

        return $message;
    }
356665
public function formatException(\Exception $e)
    {
        $message = $e->getMessage();
        if (!$e instanceof PsyException) {
            if ($message === '') {
                $message = \get_class($e);
            } else {
                $message = \sprintf('%s with message \'%s\'', \get_class($e), $message);
            }
        }

        $message = \preg_replace(
            "#(\\w:)?(/\\w+)*/src/Execution(?:Loop)?Closure.php\(\d+\) : eval\(\)'d code#",
            "eval()'d code",
            \str_replace('\\', '/', $message)
        );

        $message = \str_replace(" in eval()'d code", ' in Psy Shell code', $message);

        $severity = ($e instanceof \ErrorException) ? $this->getSeverity($e) : 'error';

        return \sprintf('<%s>%s</%s>', $severity, OutputFormatter::escape($message), $severity);
    }
72368
protected function determineExceptionType(Throwable $exception): string
	{
		if($exception instanceof ErrorException)
		{
			$code = $exception->getCode();

			$codes =
			[
				E_ERROR             => 'Fatal Error',
				E_PARSE             => 'Parse Error',
				E_COMPILE_ERROR     => 'Compile Error',
				E_COMPILE_WARNING   => 'Compile Warning',
				E_STRICT            => 'Strict Mode Error',
				E_NOTICE            => 'Notice',
				E_WARNING           => 'Warning',
				E_RECOVERABLE_ERROR => 'Recoverable Error',
				E_DEPRECATED        => 'Deprecated',
				E_USER_NOTICE       => 'Notice',
				E_USER_WARNING      => 'Warning',
				E_USER_ERROR        => 'Error',
				E_USER_DEPRECATED   => 'Deprecated',
			];

			return in_array($code, array_keys($codes)) ? $codes[$code] : 'ErrorException';
		}

		return get_class($exception);
	}
430192
public function fromArray(array $error)
    {

        // extract the array with the error information
        list ($type, $message, $file, $line) = array_values($error);

        // initialize and return the error instance
        return new Error($type, $message, $file, $line);
    }
830443
public function alpha($error) {
        if ($this->_exist) {
            array_push($this->_constraints, ['type' => self::ALPHA, 'message' => $error]);
        }

        return $this;
    }
1121395
public static function logException( \Exception $error ) {

		// fatal errors will already have been error_log()'d
		if( !static::isFatal($error) ) {
			$location = $error->getFile(). ':'. $error->getLine();
			// type hinting error - make sure we give the correct location
			if( ($error instanceof \InvalidArgumentException) && ($error->getPrevious() instanceof \ErrorException) )
				$location = $error->getPrevious()->getFile(). ':'. $error->getPrevious()->getLine();
			error_log(get_class($error). ': '. $error->getMessage(). " [{$location}]");
		}

	}
819664
protected function format_exception( Exception $exception ) {
		$string = get_class( $exception );

		if ( ! empty( $exception->getMessage() ) ) {
			$string .= " : {$exception->getMessage()}";
		}

		if ( ! empty( $exception->getCode() ) ) {
			$string .= " (#{$exception->getCode()})";
		}

		return $string;
	}
66367
public function transform(Exception $exception)
    {
        if ($exception instanceof ExceptionInterface) {
            $exception = new BadRequestHttpException($exception->getMessage());
        }

        return $exception;
    }
835104
protected static function codeToException($code)
    {
        $codes = array(
            E_ERROR => 'E_ERROR',
            E_WARNING => 'E_WARNING',
            E_NOTICE => 'E_NOTICE',
            E_USER_ERROR => 'E_USER_ERROR',
            E_USER_WARNING => 'E_USER_WARNING',
            E_USER_NOTICE => 'E_USER_NOTICE',
            E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
            E_DEPRECATED => 'E_DEPRECATED',
            E_USER_DEPRECATED => 'E_USER_DEPRECATED',
        );

        if (isset($codes[$code])) {
            return $codes[$code];
        }

        return 'Unknown';
    }
1293328
public function setError($error)
    {
        if (isset($error) && !$error instanceof \Error && !$error instanceof \Exception) {
            $type = (is_object($error) ? get_class($error) . ' ' : '') . gettype($error);
            trigger_error("Excpeted an Error or Exception, got a $type", E_USER_WARNING);
            return;
        }
        
        $this->error = $error;
    }
941584
public function fromException(\Exception $e)
    {
        return new Error(E_EXCEPTION, $e->__toString(), $e->getFile(), $e->getLine(), $e->getCode());
    }
550621
public static function errorToString($error) {
        if (!is_int($error)) throw new IllegalTypeException('Illegal type of parameter $error: '.gettype($error));

        if (key_exists($error, self::$win32Errors))
            return self::$win32Errors[$error][0];
        return (string) $error;
    }
558923
public static function create(Error $error)
	{
		// Handle pre-defined single codes
		switch ($error->code)
		{
			case Error::CODE_PARSE_ERROR:
				return new ParseErrorException($error);
			case Error::CODE_INVALID_REQUEST:
				return new InvalidRequestException($error);
			case Error::CODE_METHOD_NOT_FOUND:
				return new MethodNotFoundException($error);
			case Error::CODE_INVALID_PARAMS:
				return new InvalidParamsException($error);
			case Error::CODE_INTERNAL_ERROR:
				return new InternalErrorException($error);
		}

		// Check for server error exceptions
		if ($error->code >= -32099 && $error->code <= -32000)
			return new ServerErrorException($error);

		// Implementation-specific
		return new ResponseErrorException($error);
	}
1018882
public function transform(Exception $exception)
    {
        if ($exception instanceof TokenMismatchException) {
            $exception = new BadRequestHttpException($exception->getMessage() ?: 'CSRF token validation failed.', $exception, $exception->getCode());
        }

        return $exception;
    }