@param Exception\Exception $e
@param string $fallbackClass

@return \MongoException
336878
public static function toLegacy(Exception\Exception $e, $fallbackClass = 'MongoException')
    {
        $message = $e->getMessage();
        $code = $e->getCode();

        switch (get_class($e)) {
            case Exception\AuthenticationException::class:
            case Exception\ConnectionException::class:
            case Exception\ConnectionTimeoutException::class:
            case Exception\SSLConnectionException::class:
                $class = 'MongoConnectionException';
                break;

            case Exception\BulkWriteException::class:
            case Exception\WriteException::class:
                $writeResult = $e->getWriteResult();
                // attempt to retrieve write error
                if ($writeResult instanceof WriteResult && is_array($writeResult->getWriteErrors()) && $writeResult->getWriteErrors() !== []) {
                    $writeError = $writeResult->getWriteErrors()[0];
                    if ($writeError instanceof WriteError) {
                        $message = $writeError->getMessage();
                        $code = $writeError->getCode();
                    }
                }

                switch ($code) {
                    // see https://github.com/mongodb/mongo-php-driver-legacy/blob/ad3ed45739e9702ae48e53ddfadc482d9c4c7e1c/cursor_shared.c#L540
                    case 11000:
                    case 11001:
                    case 12582:
                        $class = 'MongoDuplicateKeyException';
                        break;
                    default:
                        $class = 'MongoCursorException';
                }
                break;

            case Exception\ExecutionTimeoutException::class:
                $class = 'MongoExecutionTimeoutException';
                break;

            default:
                $class = $fallbackClass;
        }

        if (strpos($message, 'No suitable servers found') !== false) {
            return new \MongoConnectionException($message, $code, $e);
        }

        if ($message === "cannot use 'w' > 1 when a host is not replicated") {
            return new \MongoWriteConcernException($message, $code, $e);
        }

        return new $class($message, $code, $e);
    }
1148706
private function parseResultItem(
        Crawler $resultItemDiv,
        $paramName,
        $className,
        $fallbackUrl = null
    ) {
        $filter = 'h2[itemprop=name] a, h2[itemprop=name], .name a';

        $resultItemA = $resultItemDiv->filter($filter)->first();

        if ($resultItemA->count() > 0) {
            if ($resultItemA->nodeName() == "a") {
                $url = $resultItemA->attr('href');
            } elseif ($resultItemA->nodeName() == "h2" && $fallbackUrl != null) {
                $url = $fallbackUrl;
            }
        } else {
            throw new \Exception("Can't detect title of item!");
        }

        if (! $url) {
            return null;
        }

        $resultItem = new ResultItem();

        $resultItem->setId(ParseHelper::getParamFromLink($url, $paramName));
        $resultItem->setName($resultItemA->text());
        $resultItem->setInfo(strip_tags($resultItemDiv->filter($className)->first()->text()));

        return $resultItem;
    }
265782
private static function getErrorObject( $e ) : \stdClass
	{
		$config = config('system.errors');
		$error = new \stdClass;
		$error->message = $e->getMessage();
		if ($data = json_decode($error->message)) {
			$error->message = $data;
		}
		ob_start();
		$sentData = ob_get_clean();
		if ($sentData) {
			$error->data = $sentData;
		}
		if (!is_a($e,Message::class)) {
			$error->type = self::getType($e);
			$error->file = str_replace("\\", "\\\\", $e->getFile());
			$error->line = $e->getLine();
			if ($config['backtrace']) {
				$error->trace = explode("\n", str_replace("\\", "\\\\", trim($e->getTraceAsString())));
			}
		}
		return $error;
	}
930618
protected function convertExceptionToResponse(Exception $e, Request $request)
    {
        $debug = Config::get('app.debug');

        //
        $e = FlattenException::create($e);

        $handler = new SymfonyExceptionHandler($debug);

        return SymfonyResponse::create($handler->getHtml($e), $e->getStatusCode(), $e->getHeaders());
    }
993779
protected function handleBeginTransactionException($e)
    {
        if ($this->causedByLostConnection($e)) {
            $this->reconnect();

            $this->pdo->beginTransaction();
        } else {
            throw $e;
        }
    }
743585
public function handleMicroServiceException(Exception $e)
    {
        // Determine the status code and message to return.
        if ($e instanceof HttpException) {
            return $this->handleHttpException($e);
        } elseif ($e instanceof ModelNotFoundException) {
            return $this->handleModelNotFoundException($e);
        } elseif ($e instanceof ValidationException) {
            return $this->handleValidationException($e);
        } else {
            return $this->handleGenericException($e);
        }
    }
160482
public static function render(Exception $e)
    {
        switch ($e->message) {
            case 1:
                $return = redirect()->back()->withErrors(['Not enough arguments provided']);
                break;
            case 2:
                $return = redirect()->back()->withErrors(['Object or argument is not valid']);
                break;
            case 3:
                $return = redirect()->back()->withErrors(["Object doesn't exist"]);
                break;
            case 4:
                $return = redirect()->back()->withErrors(['Object already exists']);
                break;
            case 5:
                $return = redirect()->back()->withErrors(['Object is suspended']);
                break;
            case 6:
                $return = redirect()->back()->withErrors(['Object is already unsuspended']);
                break;
            case 7:
                $return = redirect()->back()->withErrors(["Object can't be deleted because is used by the other object"]);
                break;
            case 8:
                $return = redirect()->back()->withErrors(['Object cannot be created because of hosting package limits']);
                break;
            case 9:
                $return = redirect()->back()->withErrors(['Wrong password']);
                break;
            case 10:
                $return = redirect()->back()->withErrors(['Object cannot be accessed be the user']);
                break;
            case 11:
                $return = redirect()->back()->withErrors(['Subsystem is disabled']);
                break;
            case 12:
                $return = redirect()->back()->withErrors(['Configuration is broken']);
                break;
            case 13:
                $return = redirect()->back()->withErrors(['Not enough disk space to complete the action']);
                break;
            case 14:
                $return = redirect()->back()->withErrors(['Server is to busy to complete the action']);
                break;
            case 15:
                $return = redirect()->back()->withErrors(['Connection failed. Host is unreachable']);
                break;
            case 16:
                $return = redirect()->back()->withErrors(['FTP server is not responding']);
                break;
            case 17:
                $return = redirect()->back()->withErrors(['Database server is not responding']);
                break;
            case 18:
                $return = redirect()->back()->withErrors(['RRDtool failed to update the database']);
                break;
            case 19:
                $return = redirect()->back()->withErrors(['Update operation failed']);
                break;
            case 20:
                $return = redirect()->back()->withErrors(['Service restart failed']);
                break;
            default:
                $return = redirect()->back()->withErrors([$e->getMessage()]);
        }

        return $return;
    }
779521
public function onEventError(Exception $e)
    {
        if(($this->xErrorCallback))
        {
            call_user_func_array($this->xErrorCallback, array($this->xResponse, $e));
        }
        else
        {
            throw $e;
        }
        return $this->xResponse;
    }
25028
protected function returnException(Exception $e)
    {
        $key = snake_case(class_basename($e));
        $message = $this->translate($key, $e->getMessage());

        return new ExceptionReply($message, [], $e);
    }
790404
public function setFallbackImage($fallbackImage)
    {
        $fallbackImagePath = realpath($fallbackImage);

        if(file_exists($fallbackImagePath) && is_readable($fallbackImagePath))
        {
            $this->fallbackImage = $fallbackImagePath;

            return;
        }

        throw new Exception("Default image missing or not readable, path: $fallbackImage");
    }
280076
protected function fallbackHandler(): void
	{
		$this->handle(Throwable::class, function($e): void
		{
			echo '[ ' . get_class($e) . '] ' . $e->getMessage() . ' on line [ ' . $e->getLine() . ' ] in [ ' . $e->getFile() . ' ]';

			echo PHP_EOL;

			echo $e->getTraceAsString();
		});
	}
808489
protected function convertExceptionToResponse(Exception $e)
    {
        $e = FlattenException::create($e);
        $handler = new SymfonyExceptionHandler(DEBUG);
        echo $handler->getHtml($e);
    }
143732
public static function exception(Exception $e = NULL, $config = NULL)
	{
		return Kohana_Helpers_Exception::toArray($e, $config);
	}
601316
public static function fromRequestException(RequestException $e): self
    {
        $message = $e->getMessage();

        if ($e->getResponse() && JSON::isValid($responseBody = (string) $e->getResponse()->getBody())) {
            $errors = JSON::decode($responseBody, true);
            $message = $errors['error']['message'] ?? $message;
        }

        $candidates = array_filter(array_map(function ($key, $class) use ($message, $e) {
            return stripos($message, $key) !== false
                ? new $class($e->getCode(), $e)
                : null;
        }, array_keys(self::$errors), self::$errors));

        $fallback = new static($message, $e->getCode(), $e);

        return array_shift($candidates) ?? $fallback;
    }
878161
public function setFallbackMappedType($fallbackMappedType)
    {
        if (!Type::hasType($fallbackMappedType)) {
            throw TypeException::typeDoesNotExist($fallbackMappedType);
        }

        $this->fallbackMappedType = $fallbackMappedType;
    }
52461
protected function getErrorResponse(Exception $e)
    {
        switch (get_class($e)) {
            case ForbiddenException::class:
                $response = $this->forbidden(
                    new ErrorBag([new Error('Forbidden', $e->getMessage())])
                );
                break;
            default:
                $response = $this->errorResponse(
                    new ErrorBag([new Error('Bad Request', 'Request could not be served.')])
                );
        }

        return $response;
    }
1284129
protected function doException(\Exception $e)
    {
        $command = new DefaultConsoleCommand();
        $command->data = '"Error #' . $e->getCode() . ' - ' . $e->getMessage() . '"';
        $command->execute();

        $response = (new ResponseInjector)->build();
        $response = $response->withHeader('status', (string)(int)$command->result); // TODO: hack for select cli stream

        $stream = $response->getBody();
        $stream->write($command->message);

        return $response->withBody($stream);
    }