public function recognizeErrorResponseHandler($exception, $inspector, Run $run)
    {
        $app = $this->application;

        $handlerClass = PrettyPageHandler::class;
        if ($app->isCli() || false === $app->getConfig(ApplicationInterface::KEY_ERROR, ApplicationInterface::DEFAULT_ERROR)) {
            $handlerClass = PlainTextHandler::class;
        }

        if ($app instanceof Application) {
            if ($app->isSoapRequest() || $app->isXmlRequest()) {
                $handlerClass = XmlResponseHandler::class;
            } elseif ($app->isAjaxRequest() || $app->isJsonRequest()) {
                $handlerClass = JsonResponseHandler::class;
            }
        }

        /** @var HandlerInterface $handler */
        $handler = new $handlerClass;
        $handler->setException($exception);
        $handler->setInspector($inspector);
        $handler->setRun($run);
        return $handler->handle();
    }