diff --git a/core/core.services.yml b/core/core.services.yml
index 95177ff..424ea51 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -1227,7 +1227,7 @@ services:
     tags:
       - { name: twig.loader, priority: 0 }
   twig.loader.string:
-    class: Twig_Loader_String
+    class: Drupal\Core\Template\Loader\StringLoader
     tags:
       - { name: twig.loader, priority: -100 }
   element_info:
diff --git a/core/lib/Drupal/Core/Template/Loader/StringLoader.php b/core/lib/Drupal/Core/Template/Loader/StringLoader.php
new file mode 100644
index 0000000..d24b9bf
--- /dev/null
+++ b/core/lib/Drupal/Core/Template/Loader/StringLoader.php
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Template\Loader\StringLoader.
+ */
+
+namespace Drupal\Core\Template\Loader;
+
+/**
+ * Loads string templates, also known as inline templates.
+ *
+ * This loader is intended to be used in a Twig loader chain and whitelists
+ * string templates that begin with the following comment:
+ * @code
+ * {# inline_template_start #}
+ * @endcode
+ *
+ * This class override ensures that the string loader behaves as expected in
+ * the loader chain. If Twig's string loader is used as is, any string (even a
+ * reference to a file-based Twig template) is treated as a valid template and
+ * is rendered instead of a \Twig_Error_Loader exception being thrown.
+ *
+ * @see \Drupal\Core\Template\TwigEnvironment::renderInline()
+ * @see \Drupal\Core\Render\Element\InlineTemplate
+ * @see twig_render_template()
+ */
+class StringLoader extends \Twig_Loader_String {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function exists($name) {
+    if (strpos($name, '{# inline_template_start #}') === 0) {
+      return TRUE;
+    }
+    else {
+      return FALSE;
+    }
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php
index e09d9f6..8118105 100644
--- a/core/lib/Drupal/Core/Template/TwigEnvironment.php
+++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php
@@ -195,8 +195,12 @@ public function getTemplateClass($name, $index = NULL) {
    *
    * @return string
    *   The rendered inline template.
+   *
+   * @see \Drupal\Core\Template\Loader\StringLoader::exists()
    */
   public function renderInline($template_string, array $context = array()) {
+    // Prefix all inline templates with a special comment.
+    $template_string = '{# inline_template_start #}' . $template_string;
     return $this->loadTemplate($template_string, NULL)->render($context);
   }
 
diff --git a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php
index 8edb4b2..b2e18d9 100644
--- a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php
+++ b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php
@@ -65,5 +65,21 @@ public function testInlineTemplate() {
     $this->assertEqual(drupal_render($element_copy), 'test-with-context muuh');
   }
 
+  /**
+   * Tests that exceptions are thrown when a template is not found.
+   */
+  public function testTemplateNotFoundException() {
+    /** @var \Drupal\Core\Template\TwigEnvironment $environment */
+    $environment = \Drupal::service('twig');
+
+    try {
+      $environment->loadTemplate('this-template-does-not-exist.html.twig')->render(array());
+      $this->fail('Did not throw an exception as expected.');
+    }
+    catch (\Twig_Error_Loader $e) {
+      $this->assertTrue(strpos($e->getMessage(), 'Template "this-template-does-not-exist.html.twig" is not defined') === 0);
+    }
+  }
+
 }
 
diff --git a/core/modules/system/tests/modules/common_test/templates/common-test-render-element.html.twig b/core/modules/system/tests/modules/common_test/templates/common-test-render-element.html.twig
new file mode 100644
index 0000000..ae00c8e
--- /dev/null
+++ b/core/modules/system/tests/modules/common_test/templates/common-test-render-element.html.twig
@@ -0,0 +1,12 @@
+{#
+/**
+ * @file
+ * Default theme implementation for the common test render element.
+ *
+ * Available variables:
+ * - foo: A render array.
+ *
+ * @ingroup themeable
+ */
+#}
+{{ foo }}
