title: Symfony 2.7 custom exception handler
body: <p>I'm trying to use a custom controller for exception handling in my Symfony 2.7 project, but I'getting this error: <code>Type error: Too few arguments to function Symfony\Bundle\TwigBundle\Controller\ExceptionController::__construct()</code></p>
  
  <p>I have set the exception class like this:</p>
  
  <pre><code>twig:
      exception_controller: MyProject\MainBundle\Controller\MyProjectExceptionController::showException 
  </code></pre>
  
  <p>I know I have to configure a service to pass the correct arguments to the constructor. So I have the follwing configuration in config.yml:</p>
  
  <pre><code>services:
      myproject.twig.controller.exception: 
          class: MyProject\MainBundle\Controller\MyProjectExceptionController 
          arguments: [@twig, %kernel.debug%]
  </code></pre>
  
  <p>I have read many SO's answers on the subject and seen that there is some changes in this configuration between Symfony's versions. I've tried also <code>app.configuration_exception</code> and some other options.</p>
  
  <p>Anyone knows what is the correct configuration specifically for Symfony 2.7 ? </p>
  
  <p><strong>Edit</strong></p>
  
  <p>Answering @Constantin:</p>
  
  <p>Actually I was still doing initial tests. So I basically copied Twig's ExceptionControler, and stripped all but showAction and included a test environment variable in order to see if everything was working fine. This is the result:</p>
  
  <pre><code>&lt;?php
  
  namespace MyProject\MainBundle\Controller;
  
  use Symfony\Bundle\TwigBundle\Controller\ExceptionController;
  
  use Symfony\Component\HttpKernel\Exception\FlattenException;
  use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\HttpFoundation\Response;
  //use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
  //use Symfony\Component\Templating\TemplateReferenceInterface;
  //use Twig\Environment;
  //use Twig\Error\LoaderError;
  //use Twig\Loader\ExistsLoaderInterface;
  
  class MyProjectExceptionController extends ExceptionController {
  
      public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
      {
          $currentContent = $this-&gt;getAndCleanOutputBuffering($request-&gt;headers-&gt;get('X-Php-Ob-Level', -1));
          $showException = $request-&gt;attributes-&gt;get('showException', $this-&gt;debug); // As opposed to an additional parameter, this maintains BC
  
          $code = $exception-&gt;getStatusCode();
  
          return new Response($this-&gt;twig-&gt;render(
              (string) $this-&gt;findTemplate($request, $request-&gt;getRequestFormat(), $code, $showException),
              array(
                  'status_code' =&gt; $code,
                  'status_text' =&gt; isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
                  'exception' =&gt; $exception,
                  'logger' =&gt; $logger,
                  'currentContent' =&gt; $currentContent,
                  'test' =&gt; "TEST"
              )
              ), 200, array('Content-Type' =&gt; $request-&gt;getMimeType($request-&gt;getRequestFormat()) ?: 'text/html'));
      }
  }
  </code></pre>