Answers.Body: <p>You're searching in the URI for a param with a key called <code>search</code>:</p>
  
  <pre><code>{% set token = craft.request.getParam('search') %}
  </code></pre>
  
  <p>But the in the URI it's called <code>token</code>:</p>
  
  <pre><code>REQUEST_URI=/en/book/poll-availability?token=9923444c-13b4-41bb-b7ab-9e339277bacc&amp;iframe=true&amp;room-urns=
  </code></pre>
  
  <p>Therefore when it's not an AJAX request this passes:</p>
  
  <pre><code>{% if (not craft.request.isAjax and not token ) %}
  </code></pre>
  
  <p>And a 404 is thrown:</p>
  
  <pre><code>{% exit 404 %}    
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-28T06:00:35.643Z
Answers.Text: Good spot and that's what I'd expect. But it's not a 404 that gets thrown, it's the exception shown in my question above.
Answers.UserDisplayName: Russ Back
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-02T20:56:44.683Z
Answers.Text: I'm seeing the same thing. {% exit 404 %} throws a runtime error in the logs, although everything looks fine on the front-end.
Answers.UserDisplayName: Eli Van Zoeren
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-25T22:23:10.127Z
Answers.LastActivityDate: 2015-09-25T22:23:10.127Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <p>Potentially just figured out why you were getting the error <code>An exception has been thrown during the rendering of a template ("")</code> which was happening to me.</p>
  
  <p>I was doing a check where I wanted the result to a 404 page within a layout <code>{% extends "_layout" %}</code>, BUT, the 404 page itself was using the layout template, so was essentially causing a loop.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-30T14:34:37.680Z
Answers.Text: This was exactly my  issue and couldn't figure out what I was doing wrong.  The default 404 template does this so, if you throw an error in your main template, you will get this error.
Answers.UserDisplayName: Eric Chantigny
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-31T22:17:31.343Z
Answers.LastActivityDate: 2016-07-31T22:17:31.343Z
Answers.UserDisplayName: joep
Body: <p>Struggling to debug this one.</p>
  
  <p>The full log is as follows:</p>
  
  <pre><code>Next exception 'Twig_Error_Runtime' with message 'An exception has been thrown during the rendering of a template ("") in "book/poll-availability" at line 4.' in /var/www/craft/app/vendor/twig/twig/lib/Twig/Template.php:355
  Stack trace:
  #0 /var/www/craft/app/vendor/twig/twig/lib/Twig/Template.php(314): Twig_Template-&gt;displayWithErrorHandling(Array, Array)
  #1 /var/www/craft/app/vendor/twig/twig/lib/Twig/Template.php(325): Twig_Template-&gt;display(Array)
  #2 /var/www/craft/app/vendor/twig/twig/lib/Twig/Environment.php(293): Twig_Template-&gt;render(Array)
  #3 /var/www/craft/app/services/TemplatesService.php(223): Twig_Environment-&gt;render('book/poll-avail...', Array)
  #4 /var/www/craft/app/controllers/BaseController.php(74): Craft\TemplatesService-&gt;render('book/poll-avail...', Array)
  #5 /var/www/craft/app/controllers/TemplatesController.php(55): Craft\BaseController-&gt;renderTemplate('book/poll-avail...', Array)
  #6 [internal function]: Craft\TemplatesController-&gt;actionRender('book/poll-avail...', Array)
  #7 /var/www/craft/app/framework/web/actions/CAction.php(109): ReflectionMethod-&gt;invokeArgs(Object(Craft\TemplatesController), Array)
  #8 /var/www/craft/app/framework/web/actions/CInlineAction.php(47): CAction-&gt;runWithParamsInternal(Object(Craft\TemplatesController), Object(ReflectionMethod), Array)
  #9 /var/www/craft/app/framework/web/CController.php(308): CInlineAction-&gt;runWithParams(Array)
  #10 /var/www/craft/app/framework/web/CController.php(286): CController-&gt;runAction(Object(CInlineAction))
  #11 /var/www/craft/app/framework/web/CController.php(265): CController-&gt;runActionWithFilters(Object(CInlineAction), Array)
  #12 /var/www/craft/app/framework/web/CWebApplication.php(282): CController-&gt;run('render')
  #13 /var/www/craft/app/framework/web/CWebApplication.php(141): CWebApplication-&gt;runController('templates/rende...')
  #14 /var/www/craft/app/etc/web/WebApp.php(279): CWebApplication-&gt;processRequest()
  #15 /var/www/craft/app/framework/base/CApplication.php(184): Craft\WebApp-&gt;processRequest()
  #16 /var/www/craft/app/index.php(62): CApplication-&gt;run()
  #17 /var/www/public-imperialhotels/en/index.php(22): require_once('/var/www/craft/...')
  #18 {main}
  REQUEST_URI=/en/book/poll-availability?token=9923444c-13b4-41bb-b7ab-9e339277bacc&amp;iframe=true&amp;room-urns=
  </code></pre>
  
  <p>And the template in question looks like this:</p>
  
  <pre><code>{% set token = craft.request.getParam('search') %}
  
  {% if (not craft.request.isAjax and not token ) %}
      {% exit 404 %}
  {% endif %}
  
  {% hook 'microsGetAvailabilityResults' %}
  
  {% header 'Content-Type: application/json' %}
  
  {% set data = {
      'complete': results.complete,
      'urn': results.urn,
      'pollUrl': craft.request.url ~ '?' ~ craft.request.queryStringWithoutPath
  } %}
  
  {{ data | json_encode | raw }}
  </code></pre>
  
  <p>So line 4 specifically is this:</p>
  
  <pre><code>    {% exit 404 %}
  </code></pre>
  
  <p>That should only be called if <code>token</code> is blank and as you can see from the <code>REQUEST_URI</code>, it should be set:</p>
  
  <pre><code>REQUEST_URI=/en/book/poll-availability?token=9923444c-13b4-41bb-b7ab-9e339277bacc&amp;iframe=true&amp;room-urns=
  </code></pre>
  
  <p>Any suggestions?</p>
  
  <p>What's most frustrating is that this has been picked up in server log monitoring on a live box and we can't replicate it.</p>
  
  <p>The template exits correctly if we hit the URL with a non-Ajax request and if no token is defined, so what gives?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-25T14:57:23.927Z
Comments.Text: I tracked this down further to happen only when the page is run through Google Translate. Still not clear on why the error reporting shows no reason for the error though.
Comments.UserDisplayName: Russ Back
Tags: <templating><error-handling>
Title: An exception has been thrown during the rendering of a template ("")
ThreadText: # An exception has been thrown during the rendering of a template ("")
  
  (Asked by: username_0 on 2015-09-25)
  
  Struggling to debug this one.
  
  The full log is as follows:
  
  ```
  Next exception 'Twig_Error_Runtime' with message 'An exception has been thrown during the rendering of a template ("") in "book/poll-availability" at line 4.' in /var/www/craft/app/vendor/twig/twig/lib/Twig/Template.php:355
  Stack trace:
  #0 /var/www/craft/app/vendor/twig/twig/lib/Twig/Template.php(314): Twig_Template->displayWithErrorHandling(Array, Array)
  #1 /var/www/craft/app/vendor/twig/twig/lib/Twig/Template.php(325): Twig_Template->display(Array)
  #2 /var/www/craft/app/vendor/twig/twig/lib/Twig/Environment.php(293): Twig_Template->render(Array)
  #3 /var/www/craft/app/services/TemplatesService.php(223): Twig_Environment->render('book/poll-avail...', Array)
  #4 /var/www/craft/app/controllers/BaseController.php(74): Craft\TemplatesService->render('book/poll-avail...', Array)
  #5 /var/www/craft/app/controllers/TemplatesController.php(55): Craft\BaseController->renderTemplate('book/poll-avail...', Array)
  #6 [internal function]: Craft\TemplatesController->actionRender('book/poll-avail...', Array)
  #7 /var/www/craft/app/framework/web/actions/CAction.php(109): ReflectionMethod->invokeArgs(Object(Craft\TemplatesController), Array)
  #8 /var/www/craft/app/framework/web/actions/CInlineAction.php(47): CAction->runWithParamsInternal(Object(Craft\TemplatesController), Object(ReflectionMethod), Array)
  #9 /var/www/craft/app/framework/web/CController.php(308): CInlineAction->runWithParams(Array)
  #10 /var/www/craft/app/framework/web/CController.php(286): CController->runAction(Object(CInlineAction))
  #11 /var/www/craft/app/framework/web/CController.php(265): CController->runActionWithFilters(Object(CInlineAction), Array)
  #12 /var/www/craft/app/framework/web/CWebApplication.php(282): CController->run('render')
  #13 /var/www/craft/app/framework/web/CWebApplication.php(141): CWebApplication->runController('templates/rende...')
  #14 /var/www/craft/app/etc/web/WebApp.php(279): CWebApplication->processRequest()
  #15 /var/www/craft/app/framework/base/CApplication.php(184): Craft\WebApp->processRequest()
  #16 /var/www/craft/app/index.php(62): CApplication->run()
  #17 /var/www/public-imperialhotels/en/index.php(22): require_once('/var/www/craft/...')
  #18 {main}
  REQUEST_URI=/en/book/poll-availability?token=9923444c-13b4-41bb-b7ab-9e339277bacc&iframe=true&room-urns=
  
  ```
  
  And the template in question looks like this:
  
  ```
  {% set token = craft.request.getParam('search') %}
  
  {% if (not craft.request.isAjax and not token ) %}
      {% exit 404 %}
  {% endif %}
  
  {% hook 'microsGetAvailabilityResults' %}
  
  {% header 'Content-Type: application/json' %}
  
  {% set data = {
      'complete': results.complete,
      'urn': results.urn,
      'pollUrl': craft.request.url ~ '?' ~ craft.request.queryStringWithoutPath
  } %}
  
  {{ data | json_encode | raw }}
  
  ```
  
  So line 4 specifically is this:
  
  ```
      {% exit 404 %}
  
  ```
  
  That should only be called if `token` is blank and as you can see from the `REQUEST_URI`, it should be set:
  
  ```
  REQUEST_URI=/en/book/poll-availability?token=9923444c-13b4-41bb-b7ab-9e339277bacc&iframe=true&room-urns=
  
  ```
  
  Any suggestions?
  
  What's most frustrating is that this has been picked up in server log monitoring on a live box and we can't replicate it.
  
  The template exits correctly if we hit the URL with a non-Ajax request and if no token is defined, so what gives?
  
  **Tags:** templating, error-handling
  
  > **Comments:**
  > **username_0**: I tracked this down further to happen only when the page is run through Google Translate. Still not clear on why the error reporting shows no reason for the error though.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-09-25. Score: 2
  
  You're searching in the URI for a param with a key called `search`:
  
  ```
  {% set token = craft.request.getParam('search') %}
  
  ```
  
  But the in the URI it's called `token`:
  
  ```
  REQUEST_URI=/en/book/poll-availability?token=9923444c-13b4-41bb-b7ab-9e339277bacc&iframe=true&room-urns=
  
  ```
  
  Therefore when it's not an AJAX request this passes:
  
  ```
  {% if (not craft.request.isAjax and not token ) %}
  
  ```
  
  And a 404 is thrown:
  
  ```
  {% exit 404 %}    
  
  ```
  
  > **Comments:**
  > **username_0**: Good spot and that's what I'd expect. But it's not a 404 that gets thrown, it's the exception shown in my question above.  
  > **username_2**: I'm seeing the same thing. {% exit 404 %} throws a runtime error in the logs, although everything looks fine on the front-end.  
  
  ---
  
  ### Answer by username_3 on 2016-07-31. Score: 2
  
  Potentially just figured out why you were getting the error `An exception has been thrown during the rendering of a template ("")` which was happening to me.
  
  I was doing a check where I wanted the result to a 404 page within a layout `{% extends "_layout" %}`, BUT, the 404 page itself was using the layout template, so was essentially causing a loop.
  
  > **Comments:**
  > **username_4**: This was exactly my  issue and couldn't figure out what I was doing wrong.  The default 404 template does this so, if you throw an error in your main template, you will get this error.  
  
  ---
  
  