Converts an exception to an array.

@param \Exception $ex
@return array
772599
public function convert(\Exception $ex)
    {
        $exceptions = array();

        do {
            $exceptions[] = $this->convertException($ex);
        } while (null !== $ex = $ex->getPrevious());

        return $exceptions;
    }
772740
private function convertException(Exception $e)
    {
        $data = [];
        $data['message']  = $e->getMessage();
        $data['code']     = $e->getCode();
        $data['trace']    = $this->filterTrace($e->getTrace());
        $data['status']   = Response::HTTP_INTERNAL_SERVER_ERROR;

        // determine the relevant file
        $firstTraceEntry = !empty($data['trace']) ? reset($data['trace']) : null;
        if ($firstTraceEntry !== null && isset($firstTraceEntry['file']) && isset($firstTraceEntry['line'])) {
            $data['file'] = $firstTraceEntry['file'];
            $data['line'] = $firstTraceEntry['line'];
        }
        else {
            $data['file'] = $e->getFile();
            $data['line'] = $e->getLine();
        }

        if ($e instanceof HttpException) {
            $data['status'] = $e->getStatusCode() ?: Response::HTTP_INTERNAL_SERVER_ERROR;
        }
        else if ($e instanceof QueryException) {
            $data['ansiCode']   = isset($e->errorInfo[0]) ? $e->errorInfo[0] : null;
            $data['driverCode'] = isset($e->errorInfo[1]) ? $e->errorInfo[1] : null;
            if (!empty($e->errorInfo[2])) {
                $data['message'] = $e->errorInfo[2];
            }
            $data['sql'] = $e->getDump();
        }

        return $data;
    }
347904
protected function convertExceptionToResponse(Exception $e)
    {
        $headers = $this->isHttpException($e) ? $e->getHeaders() : [];
        $statusCode = $this->isHttpException($e) ? $e->getStatusCode() : 500;

        try {
            $content = config('app.debug') && class_exists(Whoops::class)
                ? $this->renderExceptionWithWhoops($e)
                : $this->renderExceptionWithSymfony($e, config('app.debug'));
        } catch (Exception $e) {
            $content = $content ?? $this->renderExceptionWithSymfony($e, config('app.debug'));
        }

        return SymfonyResponse::create(
            $content,
            $statusCode,
            $headers
        );
    }
1134472
protected function convertExceptionToArray(Exception $exception): array
    {
        $errors = [
            'exception' => get_class($exception),
            'file' => $exception->getFile(),
            'line' => $exception->getLine(),
            'trace' => collect($exception->getTrace())->map(function ($trace) {
                return Arr::except($trace, ['args']);
            })->all(),
        ];

        return [
            'message' => $exception->getMessage() ?: 'Server error',
            'errors' => config('app.debug') ? $errors : [],
        ];
    }
567699
protected function getTransformed(Exception $exception)
    {
        foreach ($this->make((array) $this->getConfigItem('transformers')) as $transformer) {
            $exception = $transformer->transform($exception);
        }

        return $exception;
    }
652162
private static function handleRequestException (Throwable $ex) {
        ob_clean();
        $response = get_response();
        $response->clear();
        $errorRoutes = self::$errorRoutes->getRoutes();
        if (!empty($errorRoutes)) {
            foreach ($errorRoutes as $errorRoute) {
                $routeResult = self::executeAction($errorRoute->getAction(), array_merge($_REQUEST, $errorRoute->getParameters(), [Throwable::class => $ex, Exception::class => $ex]));
                if (!empty($routeResult)) {
                    $response->content($routeResult);
                }
            }
            $response->send();
        }
        else {
            throw $ex;
        }
    }
806745
protected function handleException(\Exception $e)
    {
        $data = [];

        if ($this->controller->app->get('system.debug')) {
            $data['exception'] = get_class($e);
            $data['backtrace'] = BacktraceHelper::normalizeBacktraces($e->getTrace());

            foreach ($data['backtrace'] as &$datum) {
                unset($datum['pathname']);
            }

            if (class_exists(DebuggerHelper::class)) {
                try {
                    $data['debug_messages'] = (array) DebuggerHelper::getInstance()->get('debug.messages');
                } catch (\Exception $e) {
                    // None
                }
            }
        }

        $this->controller->setResponse(
            $this->controller
                ->getResponse()
                ->withStatus(
                    ErrorManager::normalizeCode($e->getCode()),
                    ErrorManager::normalizeMessage($e->getMessage())
                )
        );

        $message = !WINDWALKER_DEBUG ? $e->getMessage() : sprintf(
            '#%d %s - File: %s (%d)',
            $e->getCode(),
            $e->getMessage(),
            $e->getFile(),
            $e->getLine()
        );

        return new JsonBuffer($message, $data, false, $e->getCode());
    }
259260
public static function writeException(\Exception $ex)
	{
		$response = array(
			'exception' => get_class($ex),
			'message' => $ex->getMessage(),
			'code' => $ex->getCode(),
		);
		static::writeJson($response);
	}
1314805
public function processException($exception)
    {
        $requestDetails = [
            'type' => 'exception',
            'data' => json_encode([
                'exception_content' => $exception->getMessage() ?? 'No message',
                'exception_trace' => $exception->getTrace(),
                'exception_file' => $exception->getFile(),
                'exception_line' => $exception->getLine(),
            ]),
        ];

        return array_merge($this->baseRequest(), $requestDetails);
    }
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;
    }
1293492
public function handleAndResponseException(\Exception $ex)
    {

        $response = '';
        switch (true) {
            case $ex instanceof \Illuminate\Database\Eloquent\ModelNotFoundException:
                $response = $this->respondNotFound('Record not found');
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException:
                $response = $this->respondNotFound("Not found");
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException:
                $response = $this->respondForbidden("Access denied");
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\BadRequestHttpException:
                $response = $this->respondBadRequest("Bad request");
                break;
            case $ex instanceof BadMethodCallException:
                $response = $this->respondBadRequest("Bad method Call");
                break;
            case $ex instanceof \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException:
                $response = $this->respondForbidden("Method not found");
                break;
            case $ex instanceof \Illuminate\Database\QueryException:
                $response = $this->respondValidationError("Some thing went wrong with your query", [$ex->getMessage()]);
                break;
            case $ex instanceof \Illuminate\Http\Exceptions\HttpResponseException:
                $response = $this->respondInternalError("Something went wrong with our system", [$ex->getMessage()]);
                break;
            case $ex instanceof \Illuminate\Auth\AuthenticationException:
                $response = $this->respondUnauthorized("Unauthorized request");
                break;
            case $ex instanceof \Illuminate\Validation\ValidationException:
                $response = $this->respondValidationError("In valid request", [$ex->getMessage()]);
                break;
            case $ex instanceof NotAcceptableHttpException:
                $response = $this->respondUnauthorized("Unauthorized request");
                break;
            case $ex instanceof \Illuminate\Validation\UnauthorizedException:
                $response = $this->respondUnauthorized("Unauthorized request", [$ex->getMessage()]);
                break;
            case $ex instanceof \Exception:
                $response = $this->respondInternalError("Something went wrong with our system", [$ex->getMessage()]);
                break;
        }
        return $response;
    }
1193353
private function getExceptionData($exception)
    {
        $data = [];

        $data['enviroment'] = env('APP_ENV');
        $data['host'] = Request::server('SERVER_NAME');
        $data['method'] = Request::method();
        $data['fullUrl'] = Request::fullUrl();
        $data['exception'] = $exception->getMessage();
        $data['error'] = $exception->getTraceAsString();
        $data['line'] = $exception->getLine();
        $data['file'] = $exception->getFile();
        $data['class'] = get_class($exception);
        $data['storage'] = [
            'SERVER' => Request::server(),
            'GET' => Request::query(),
            'POST' => $_POST,
            'FILE' => Request::file(),
            'OLD' => Request::hasSession() ? Request::old() : [],
            'COOKIE' => Request::cookie(),
            'SESSION' => Request::hasSession() ? Session::all() : [],
            'HEADERS' => Request::header(),
        ];

        $data['storage'] = array_filter($data['storage']);

        $count = $this->config['count'];
        $lines = file($data['file']);
        $data['exegutor'] = [];

        for ($i = -1 * abs($count); $i <= abs($count); $i++) {
            $data['exegutor'][] = $this->getLineInfo($lines, $data['line'], $i);
        }
        $data['exegutor'] = array_filter($data['exegutor']);

        // to make symfony exception more readable
        if ($data['class'] == 'Symfony\Component\Debug\Exception\FatalErrorException') {
            preg_match("~^(.+)' in ~", $data['exception'], $matches);
            if (isset($matches[1])) {
                $data['exception'] = $matches[1];
            }
        }

        return $data;
    }
672729
public function RenderException($Ex) {
      if ($this->DeliveryMethod() == DELIVERY_METHOD_XHTML) {
         try {
            if (is_a($Ex, 'Gdn_UserException')) {
               Gdn::Dispatcher()
                  ->PassData('Code', $Ex->getCode())
                  ->PassData('Exception', $Ex->getMessage())
                  ->PassData('Message', $Ex->getMessage())
                  ->PassData('Trace', $Ex->getTraceAsString())
                  ->PassData('Url', Url())
                  ->PassData('Breadcrumbs', $this->Data('Breadcrumbs', array()))
                  ->Dispatch('/home/error');
            } else {
               switch ($Ex->getCode()) {
                  case 401:
                     Gdn::Dispatcher()
                        ->PassData('Message', $Ex->getMessage())
                        ->PassData('Url', Url())
                        ->Dispatch('DefaultPermission');
                     break;
                  case 404:
                     Gdn::Dispatcher()
                        ->PassData('Message', $Ex->getMessage())
                        ->PassData('Url', Url())
                        ->Dispatch('Default404');
                     break;
                 default:
                    Gdn_ExceptionHandler($Ex);
               }
            }
            
            
         } catch(Exception $Ex2) {
            Gdn_ExceptionHandler($Ex);
         }
         return;
      }

      // Make sure the database connection is closed before exiting.
      $this->Finalize();
      $this->SendHeaders();

      $Code = $Ex->getCode();
      $Data = array('Code' => $Code, 'Exception' => $Ex->getMessage(), 'Class' => get_class($Ex));
      
      if (Debug()) {
         if ($Trace = Trace()) {
            $Data['Trace'] = $Trace;
         }
         
         if (!is_a($Ex, 'Gdn_UserException'))
            $Data['StackTrace'] = $Ex->getTraceAsString();
         
         $Data['Data'] = $this->Data;
      }
      
      // Try cleaning out any notices or errors.
      @@ob_clean();
      

      if ($Code >= 400 && $Code <= 505)
         header("HTTP/1.0 $Code", TRUE, $Code);
      else
         header('HTTP/1.0 500', TRUE, 500);

      
      switch ($this->DeliveryMethod()) {
         case DELIVERY_METHOD_JSON:
            if (($Callback = $this->Request->GetValueFrom(Gdn_Request::INPUT_GET, 'callback', FALSE)) && $this->AllowJSONP()) {
               header('Content-Type: application/javascript', TRUE);
               // This is a jsonp request.
               exit($Callback.'('.json_encode($Data).');');
            } else {
               header('Content-Type: application/json', TRUE);
               // This is a regular json request.
               exit(json_encode($Data));
            }
            break;
//         case DELIVERY_METHOD_XHTML:
//            Gdn_ExceptionHandler($Ex);
//            break;
         case DELIVERY_METHOD_XML:
            header('Content-Type: text/xml', TRUE);
            array_map('htmlspecialchars', $Data);
            exit("<Exception><Code>{$Data['Code']}</Code><Class>{$Data['Class']}</Class><Message>{$Data['Exception']}</Message></Exception>");
            break;
         default:
            header('Content-Type: text/plain', TRUE);
            exit($Ex->getMessage());
      }
   }
236692
public static function e2Array($e) {
        is_object($e) and $e = [
            'message' => $e->getMessage(),
            'file' => $e->getFile(),
            'line' => $e->getLine(),
            'trace' => $e->getTraceAsString(),
            'type' => $e->getCode()
        ];
        return $e;
    }
1150989
public function getResultsAsArray()
    {
        $new = array();
        foreach ((array) $this->results as $result) {
            if ($result instanceof Object)
                $new[] = $result->toArray();
            else if (is_array($result))
                return $this->results;
            else
                throw new Exception('Cannot convert to array: '.ClassUtils::getQualifiedType($result));
        }
        return $new;
    }
474311
private function getExceptionData($exception)
    {
        $data = [];

        $data['host'] = Request::server('HTTP_HOST');
        $data['method'] = Request::method();
        $data['fullUrl'] = Request::fullUrl();
        if (php_sapi_name() === 'cli') {
            $data['host'] = parse_url(config('app.url'), PHP_URL_HOST);
            $data['method'] = 'CLI';
        }
        $data['exception'] = $exception->getMessage();
        $data['error'] = $exception->getTraceAsString();
        $data['line'] = $exception->getLine();
        $data['file'] = $exception->getFile();
        $data['class'] = get_class($exception);
        $data['storage'] = array(
            'SERVER'  => Request::server(),
            'GET'     => Request::query(),
            'POST'    => $_POST,
            'FILE'    => Request::file(),
            'OLD'     => Request::hasSession() ? Request::old() : [],
            'COOKIE'  => Request::cookie(),
            'SESSION' => Request::hasSession() ? Session::all() : [],
            'HEADERS' => Request::header(),
        );

        // Remove empty, false and null values
        $data['storage'] = array_filter($data['storage']);

        // Censor sensitive field values
        array_walk_recursive($data['storage'], 'self::censorSensitiveFields');

        $count = $this->config['count'];
        
        $data['exegutor']   = [];
        $data['file_lines'] = [];
        
        $file = new SplFileObject($data['file']);
        for ($i = -1 * abs($count); $i <= abs($count); $i++) {
            list($line, $exegutorLine) = $this->getLineInfo($file, $data['line'], $i);
            if (!$line && !$exegutorLine) {
                continue;
            }
            $data['exegutor'][] = $exegutorLine;
            $data['file_lines'][$data['line'] + $i] = $line;
        }

        // to make Symfony exception more readable
        if ($data['class'] == 'Symfony\Component\Debug\Exception\FatalErrorException') {
            preg_match("~^(.+)' in ~", $data['exception'], $matches);
            if (isset($matches[1])) {
                $data['exception'] = $matches[1];
            }
        }

        return $data;
    }
10399
private function normalizeException(\Exception $exception) {
		$data = [
			'class'   => get_class($exception),
			'message' => $exception->getMessage(),
			'code'    => $exception->getCode(),
			'file'    => $exception->getFile() . ':' . $exception->getLine(),
		];
		$trace = $exception->getTraceAsString();
		$data['trace'] = $trace;

		$previous = $exception->getPrevious();
		if ($previous) {
			$data['previous'] = $this->normalizeException($previous);
		}

		return $data;
	}