Answers.Body: <p>Here's one way to do it – not super elegant, but it works:</p>
  
  <pre><code>{% set template %}
      {{- include('sometemplatethatdoesntexist', ignore_missing = true) -}}
  {% endset %}
  
  {% if not template %}
      {% exit 404 %}
  {% endif %}
  
  {{ template }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-05T10:34:56.523Z
Answers.LastActivityDate: 2016-04-05T11:12:57.770Z
Answers.LastEditDate: 2016-04-05T11:12:57.770Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>Attempting to include a template that doesn't exist throws HttpStatus 500 – <code>Craft\TemplateLoaderException – Unable to find the template “{template}”.</code></p>
  
  <p>This is usually fine and what you want, but is it possible to override this behaviour somehow, and make Craft throw a plain' old 404 instead?</p>
  
Tags: <templating><error-handling>
Title: Is it possible to make Craft/Twig throw 404 if a template can't be found?
ThreadText: # Is it possible to make Craft/Twig throw 404 if a template can't be found?
  
  (Asked by: username_0 on 2016-04-05)
  
  Attempting to include a template that doesn't exist throws HttpStatus 500 – `Craft\TemplateLoaderException – Unable to find the template “{template}”.`
  
  This is usually fine and what you want, but is it possible to override this behaviour somehow, and make Craft throw a plain' old 404 instead?
  
  **Tags:** templating, error-handling
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-04-05. Score: 6 | Accepted answer
  
  Here's one way to do it – not super elegant, but it works:
  
  ```
  {% set template %}
      {{- include('sometemplatethatdoesntexist', ignore_missing = true) -}}
  {% endset %}
  
  {% if not template %}
      {% exit 404 %}
  {% endif %}
  
  {{ template }}
  
  ```
  
  
  ---
  
  