handle() public method

Handle an exception.
public handle ( Exception $exception ) : Response
$exception Exception
return Symfony\Component\HttpFoundation\Response
 /**
  * {@inheritdoc}
  */
 public function handle(Exception $exception)
 {
     if ($this->rethrow) {
         throw $exception;
     }
     foreach ($this->handlers as $index => $handler) {
         try {
             if (is_string($handler)) {
                 $handler = $this->resolver->resolve($handler);
                 $this->handlers->offsetSet($index, $handler);
             } else {
                 if (is_array($handler) && is_string($handler[0])) {
                     $handler[0] = $this->resolver->resolve($handler[0]);
                     $this->handlers->offsetSet($index, $handler);
                 }
             }
             if (!$this->matchesTypehint($handler, $exception)) {
                 continue;
             }
             $result = $this->callHandler($handler, $exception);
             if ($result !== null) {
                 return $this->makeResponse($result, $exception);
             }
         } catch (Exception $newException) {
             return $this->handle($newException);
         }
     }
     return $this->makeResponse($this->defaultHandler->handle($exception), $exception);
 }
Beispiel #2
0
 protected function handleException(Exception $exception, Request $request, $type)
 {
     if ($this->errorHandler === null) {
         throw $exception;
     }
     if ($this->eventDispatcher !== null) {
         $event = new GetResponseForExceptionEvent($this, $request, $type, $exception);
         $this->eventDispatcher->dispatch(KernelEvents::EXCEPTION, $event);
         $response = $event->getResponse() ?: $this->errorHandler->handle($exception);
     } else {
         $response = $this->errorHandler->handle($exception);
     }
     try {
         return $this->filterResponse($response, $request, $type);
     } catch (Exception $e) {
         return $response;
     }
 }