Create a new 'received exception' event.

@param Throwable $exception The received exception.

@return ReceivedExceptionEvent The newly created event.
355454
public function createReceivedException(
        Throwable $exception
    ): ReceivedExceptionEvent {
        return new ReceivedExceptionEvent(
            $this->sequencer->next(),
            $this->clock->time(),
            $exception
        );
    }
1207499
protected function handleException(\Throwable $exception, RequestInterface $request): RequestException
    {
        if ($exception instanceof RequestException) {
            return $exception;
        }

        return new RequestException($request, $exception);
    }
1095739
private function callOnException(\Exception $exception)
    {
        if (is_null($this->onException)) {
            throw  $exception;
        }

        $closure = $this->onException;

        $message = $closure($this, $exception);

        return $message;
    }
573342
final public static function exceptionHandler(\Throwable $exception)
    {
        if (FEnv::isset("framework.env")) {
            throw new Server500(new \ArrayObject(array("explain" => $exception->getMessage(),
                "trace" => $exception->getTrace(), "line_error" => $exception->getLine(),
                "file_error" => $exception->getFile(), "type_error" => self::errorMap($exception->getCode()))));
        } else {
            die($exception->getMessage());
        }
    }
336011
final public static function getBaseException(\Exception $exception)
    {
        while ($exception->getPrevious() !== null) {
            $exception = $exception->getPrevious();
        }

        return $exception;
    }
593428
public function exception($exception = null)
    {
        if (!func_num_args()) {
            return $this->_exception;
        }
        $this->_exception = $exception;
        return $this;
    }
1242461
public function add($exception) {
        if($this->checkException($exception) === FALSE) {
            trigger_error(
                'Only subclasses of \Exception and implementations of \Throwable can be aggregated!',
                E_USER_ERROR
            );
        }

        $this->collection[] = $exception;
    }
52424
public function handle(\Throwable $throwable)
    {
        // Being Emitter Aware we are bound to comply to the Events Definition.
        // self::emitDebugEvent() will return null when no Emitter is present. Otherwise we'll get the Exception
        // after it's been processed by Event Listeners so we need to overwrite it here.
        if (null !== $response = $this->emitDebugEvent(definitions\Events::DEBUG_THROWABLE_BEFORE, $throwable)) {
            $throwable = $response;
        }

        // First of all run all Conditions. The method will return true if we are to prevent further execution.
        if ($this->runConditions($throwable)) {
            return;
        }

        // Whether we will quit after the loop. Set to true when one of the Delegates returns a QUIT signal.
        $quit = false;

        // Get the applicable Delegates.
        $delegates = array_intersect_key($this->delegates, array_flip($this->getApplicable()));

        // If we've got anything to call later on, proceed.
        if (!empty($delegates)) {
            // Sort the Delegates by their priority.
            $this->sort($delegates);

            // Inspect the Exception we got, which will give us an Inspector instance we can pass along.
            $inspector = $this->inspect($throwable);

            // Walk through all applicable Delegates and let them handle the Exception until done or one of them
            // returns a STOP/QUIT signal.
            foreach ($delegates as $v) {
                // If we're dealing with a Delegate instance, call its handle() method. If it's a casual callable,
                // call it and pass the Inspector as the only argument.
                $response = $v['delegate'] instanceof interfaces\Delegate
                    ? $v['delegate']->handle($inspector)
                    : call_user_func($v['delegate'], $inspector);

                // Make it easier for inheriting children to act upon the response if it's not a signal.
                $response = $this->handleDelegateResponse($response, $inspector);

                // Let's check if we've got a signal as response. If it's QUIT, we'll set a flag and handle it
                // after the loop.
                if (($response & definitions\Signals::QUIT) === definitions\Signals::QUIT) {
                    $quit = true;
                }

                // QUIT includes STOP so this will catch both situations.
                if (($response & definitions\Signals::STOP) === definitions\Signals::STOP) {
                    break;
                }
            }
        }

        // Now that we are done looping, time to attempt to emit the appropriate Event.
        $this->emitDebugEvent(definitions\Events::DEBUG_THROWABLE_AFTER, $throwable);

        // If we were told to quit and the Handler allows this, do eet.
        if ($quit and $this->doesAllowQuit()) {
            exit;
        }

        // Clear all lists. See the notes for {@see self::whitelist()} and {@see self::blacklist()} why Delegates
        // should be listed, for consistency, by Conditions *only*.
        $this->applicable = null;
        $this->whitelist  = $this->blacklist = [];
    }
455858
public function fromException( Exception $exception )
    {
        return $this->generateResponse(
            xmlrpc_encode_request(
                null,
                array(
                    'faultCode' => $exception->getCode(),
                    'faultString' => $exception->getMessage()
                )
            )
        );
    }
385355
protected function throwError($exception)
    {
        switch ($exception->getResponse()->getStatusCode()) {
            case 400:
                throw new BadRequestException($exception);
                break;

            case 401:
                throw new UnauthorizedException($exception);
                break;

            case 403:
                throw new MethodNotAllowedException($exception);
                break;

            case 404:
                throw new NotFoundException($exception);
                break;

            default:
                throw new Exception($exception);
                break;
        }
    }
1372614
public static function fromThrowable($throwable)
    {
        if ($throwable instanceof \Error) {
            $throwable = ErrorException::fromError($throwable);
        }

        if (!$throwable instanceof \Exception) {
            throw new \InvalidArgumentException('throw-up can only throw Exceptions and Errors');
        }

        return new self($throwable);
    }
215187
private function createResponseForFailedRequest(Request $request, \Throwable $exception): Response
    {
        $code = $exception->getCode() > 0 ? $exception->getCode() : Code::UNKNOWN;

        $response = RequestFailedResponseV1::create()
            ->set('ctx_request_ref', $request->generateMessageRef())
            ->set('ctx_request', $request)
            ->set('error_code', $code)
            ->set('error_name', ClassUtils::getShortName($exception))
            ->set('error_message', substr($exception->getMessage(), 0, 2048))
            ->set('stack_trace', $exception->getTraceAsString());

        if ($exception->getPrevious()) {
            $response->set('prev_error_message', substr($exception->getPrevious()->getMessage(), 0, 2048));
        }

        if ($request->has('ctx_correlator_ref')) {
            $response->set('ctx_correlator_ref', $request->get('ctx_correlator_ref'));
        }

        return $response;
    }
1260024
public function exceptionHandler(Exception $exception)
    {
        $this->logger->addError($exception->getMessage(), array($exception->getFile(), $exception->getLine()));
        exit(-1);
    }
681134
public function prepare(Exception $exception)
  {
    if ($exception instanceof NotFoundHttpException) {
      return $exception->createsClientError();
    } else if ($exception instanceof ServiceUnavailableHttpException) {
      return $exception->createsServerError();
    }

    return $exception;
  }
1276464
protected function requestExceptionHandler(Throwable $exception) : ?Throwable
    {
        if ($exception instanceof RequestException) {
            if (
                $exception->hasResponse() &&
                $exception->getResponse()->hasError()
            ) {
                return new BadRemoteCallException($exception->getResponse());
            }

            return new ConnectionException(
                $exception->getRequest(),
                $exception->getMessage(),
                $exception->getCode()
            );
        }

        return null;
    }
353800
public static function fromException(\Throwable $exception): self
    {
        return new self(
            $exception->getMessage(),
            $exception->getCode(),
            $exception
        );
    }
855300
private function parseExceptionForErrorMessages(Exception $exception)
    {
        if (! $exception instanceof BadResponseException) {
            return new ApiException($exception->getMessage(), 0, $exception);
        }

        $response = $exception->getResponse();

        if (null === $response) {
            return new ApiException('Response is NULL.', 0, $exception);
        }

        Psr7\rewind_body($response);
        $responseBody = $response->getBody()->getContents();
        $decodedResponseBody = json_decode($responseBody, true);

        if (null !== $decodedResponseBody && isset($decodedResponseBody['error']['message']['value'])) {
            $errorMessage = $decodedResponseBody['error']['message']['value'];
        } else {
            $errorMessage = $responseBody;
        }

        $this->checkWhetherRateLimitHasBeenReached($response, $errorMessage);

        return new ApiException('Error ' . $response->getStatusCode() . ': ' . $errorMessage, $response->getStatusCode(), $exception);
    }