Converts an Exception to an array in the format as returned by \Exception::getTrace().

@param   \Throwable  $throwable  The Exception to convert.
@return  array
194385
public static function throwableToArray(\Throwable $throwable) : array
    {
        return [
            'type'  => $throwable->getCode(),
            'file'  => $throwable->getFile(),
            'line'  => $throwable->getLine(),
            'class' => get_class($throwable),
            'args'  => [$throwable->getMessage()]
        ];
    }
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);
	}
499098
public static function iterableToArray($iterable): array
    {
        if (is_array($iterable)) {
            return $iterable;
        }

        if ($iterable instanceof \Traversable) {
            return iterator_to_array($iterable);
        }

        throw new \InvalidArgumentException('Iterable is expected.');
    }
910771
public function handle(\Throwable $throwable)
    {
        try {
            $response = $this->doHandler($throwable);
        } catch (\Throwable $e) {
            $response = $this->handleThrowtable($e);
        }

        return $response;
    }
449373
protected function extractExceptionData(Exception $exception)
    {
        $data = [
            'exception' => get_class($exception),
            'message'   => $exception->getMessage(),
            'code'      => $exception->getCode(),
            'file'      => $exception->getFile(),
            'line'      => $exception->getLine(),
            'trace'     => []
        ];

        foreach ($exception->getTrace() as $item) {
            if (isset($item['args']) && is_array($item['args'])) {
                $item['args'] = $this->cleanTraceArgs($item['args']);
            }
            $data['trace'][] = $item;
        }

        return $data;
    }
152594
public function addException(\Throwable $exception)
    {
        $memory = $this->getMemory();

        $exceptions = $this->unserialize($memory);

        $exceptions[] = get_class($exception) . ": " . $exception->getMessage() . " (" . $exception->getFile() . ":" . $exception->getLine() . ")";

        $data = serialize($exceptions);

        shmop_write($memory, $data, 0);
        shmop_close($memory);
    }
717577
private function formatStacktraceForExceptions($exceptions)
    {
        if (!is_array($exceptions)) {
            $exceptions = [$exceptions];
        }

        $this->root = $this->findApplicationRoot();

        $trace = '';
        foreach ($exceptions as $ex) {
            if ($ex instanceof Throwable) {
                $trace .= $this->formatExceptionStacktrace($ex);
            }
        }

        return $trace;
    }
763676
public static function convert(Throwable $throwable): ?JsonApiException
    {
        $converted = null;

        if ($throwable instanceof AuthorizationException) {
            $httpCode  = 403;
            $action    = $throwable->getAction();
            $errors    = (new ErrorCollection())
                ->addDataError(
                    'Unauthorized',
                    "You are not unauthorized for action `$action`.",
                    null,
                    null,
                    null,
                    $httpCode
                );
            $converted = new JsonApiException($errors, $httpCode, $throwable);
        } elseif ($throwable instanceof AuthenticationException) {
            $httpCode  = 401;
            $errors    = (new ErrorCollection())
                ->addDataError(
                    'Authentication failed',
                    'Authentication failed',
                    null,
                    null,
                    null,
                    $httpCode
                );
            $converted = new JsonApiException($errors, $httpCode, $throwable);
        }

        return $converted;
    }
1230024
protected function convertExceptionToArray($exception)
    {
        if (!YII_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) {
            $exception = new HttpException(500, Yii::t('yii', 'An internal server error occurred.'));
        }

        $array = [
            'code' => $exception->getCode(),
            'data' => new \stdClass(),
            'message' => $exception->getMessage(),
        ];
        if ($exception instanceof HttpException) {
            $array['code'] = $exception->statusCode;
        }
        if($exception instanceof ApiException && !empty($exception->model)){
            $array = [
                'code' => 422,
                'data' => $exception->model->getErrors(),
                'message' => 'Data Validation Failed.',
            ];
        }
        if (YII_DEBUG) {
            $array['type'] = get_class($exception);
            if (!$exception instanceof UserException) {
                $array['file'] = $exception->getFile();
                $array['line'] = $exception->getLine();
                $array['stack-trace'] = explode("\n", $exception->getTraceAsString());
                if ($exception instanceof \yii\db\Exception) {
                    $array['error-info'] = $exception->errorInfo;
                }
            }
            if (($prev = $exception->getPrevious()) !== null) {
                $array['previous'] = $this->convertExceptionToArray($prev);
            }
        }

        return $array;
    }
225836
public function formatException(\Exception $e) {
        $entry = array();

        $entry['class'] = get_class($e);
        $entry['message'] = $e->getMessage();
        $entry['file'] = $e->getFile();
        $entry['line'] = $e->getLine();
        $entry['trace'] = $e->getTraceAsString();

        return $entry;
    }
182881
public function getNormalized(\Exception $exception)
    {
        $stack = $exception->getTrace();
        $trace = [];

        foreach ($stack as $item) {
            $trace[] = [
                'invocation' => $this->getInvocation($item),
                'origin'     => $this->getOrigin($item)
            ];
        }

        return $trace;
    }
33468
private function getExceptionHandlerMethods(Exception $exception)
    {
        $class = new ReflectionClass($this);

        $handlerMethods = [];
        foreach ($class->getMethods(ReflectionMethod::IS_PROTECTED) as $method) {
            $param = current($method->getParameters());
            if ($param && $param->getClass() && $param->getClass()->isInstance($exception)) {
                $handlerMethods[] = $method;
            }
        }

        return $handlerMethods;
    }
44764
private static function serializeThrowableObject($throwable): string
    {
        $message = \sprintf(
            '[GraphQL] %s: %s[%d] (caught throwable) at %s line %s.',
            \get_class($throwable),
            $throwable->getMessage(),
            $throwable->getCode(),
            $throwable->getFile(),
            $throwable->getLine()
        );

        return $message;
    }
669783
public function exceptionHandler(\Throwable $exception)
    {
        if ($exception instanceof ResponseCode) {
            try {
                $out = $this->render($exception->getCode(), [], $exception->display());
            } catch (\Throwable $exception) {
                return $this->exceptionHandler($exception);
            }

            // debug on dev / display trace
            if (!(AbstractApp::env() != AbstractApp::PRODUCTION && ob_get_length() > 0)) {
                self::response()->addHeader('Content-Type', $this->getErrorContentType());
            }

            self::response()->setStatus($exception->getCode());
            self::response()->setBody($out);
            HttpApp::instance()->end();
        } else {
            Handler::log($exception);

            if (AbstractApp::env() != AbstractApp::PRODUCTION) {
                Handler::exceptionHandler($exception);
            } else {
                $throw = new ResponseCode($exception->getMessage(), 500, $exception);
                $this->exceptionHandler($throw);
            }
        }

        return true;
    }
876052
protected function resolveCustomRenderingOptions(\Throwable $exception): array
    {
        $renderingOptions = [];
        if (isset($this->options['defaultRenderingOptions'])) {
            $renderingOptions = $this->options['defaultRenderingOptions'];
        }
        $renderingGroup = $this->resolveRenderingGroup($exception);
        if ($renderingGroup !== null) {
            $renderingOptions = Arrays::arrayMergeRecursiveOverrule($renderingOptions, $this->options['renderingGroups'][$renderingGroup]['options']);
            $renderingOptions['renderingGroup'] = $renderingGroup;
        }
        return $renderingOptions;
    }
421331
protected function doRenderDebug(\Throwable $exception, ?string $outputBuffer = null): array
    {
        $title = Exception::getName($exception);
        $extras = '';

        $this->emit(WebErrorScreenEvents::RENDER_DEBUG, [
            'title' => &$title,
            'extras' => &$extras,
            'exception' => $exception,
            'output_buffer' => $outputBuffer,
        ]);

        $output = '';
        $chain = Exception::getChain($exception);
        $totalExceptions = count($chain);

        for ($i = 0; $i < $totalExceptions; ++$i) {
            $output .= $this->renderException($chain[$i], $i, $totalExceptions);

            if ($i === 0) {
                // render extras after the first exception
                $output .= $extras;
                $output .= $this->renderOutputBuffer($outputBuffer);
                $output .= $this->renderPlaintextTrace($exception);
            }
        }

        return [$title, $output];
    }
1056097
private function export(\Throwable $exception)
    {
        $return = [];
        $return['type'] = get_class($exception);
        $return['stack_trace'] = explode("\n", $exception->getTraceAsString());
        $return['code'] = $exception->getCode();
        $return['message'] = $exception->getMessage();

        foreach (get_object_vars($exception) as $key => $value) {
            if ($key != 'message' && $key != 'code') {
                $return['detail'][$key] = (string) $exception->$key;
            }
        }

        if (isset($return['detail'])) {
            $return['detail'] = json_encode($return['detail']);
        }

        return $return;
    }