title: Catch "Missing or incorrect CSRF cookie type." exception
body: <p>I know why this exception is thrown, this is not the problem, but I am not capable to catch this exception.</p>
  <p><em>This exception is thrown in <code>CORE/src/Http/Middleware/CsrfProtectionMiddleware.php</code> line #286:</em></p>
  <pre><code>if (!$cookie || !is_string($cookie)) {
     throw new InvalidCsrfTokenException(__d('cake', 'Missing or incorrect CSRF cookie type.'));
  }
  </code></pre>
  <p>When I check the long list of the stack in the CakePHP error window it's clear to me I cannot start to modify the CORE files as with the next CakePHP update/upgrade my modifications are lost.</p>
  <p>The only script I can modify and should be easily handled is <code>webroot/index.php</code>. It's also mentioned in the call stack in the first position:</p>
  <blockquote>
  <p>Cake\Http\Server-&gt;run ROOT/webroot/index.php:50</p>
  </blockquote>
  <p>And here I am stuck. What ever I tried:</p>
  <ul>
  <li><code>try/catch ( \Exception )</code></li>
  <li><code>try/catch ( \Cake\Http\Exception\InvalidCsrfTokenException )</code></li>
  <li>Using <code>set_exception_handler()</code></li>
  </ul>
  <p>nothing helps, this means, I always get the below error window. In this window you can see on the left the long call stack of scripts which are called until the exception is thrown. And this are even not all scripts. So it's really nested.</p>
  <p><strong>My question:</strong></p>
  <p>How can I catch this exception in the most top PHP script <code>webroot/index.php</code> - below this script are another 16 scripts called until the exception is thrown. I don't want to modify the CakePHP core files.</p>
  <p>I am running CakePHP 4.1.4</p>
  <p><a href="https://i.stack.imgur.com/xaINg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xaINg.png" alt="enter image description here" /></a></p>