diff --git a/core/core.services.yml b/core/core.services.yml
index 24fa98e..a31482e 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -1221,7 +1221,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..c943ac6
--- /dev/null
+++ b/core/lib/Drupal/Core/Template/Loader/StringLoader.php
@@ -0,0 +1,33 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Template\Loader\StringLoader.
+ */
+
+namespace Drupal\Core\Template\Loader;
+
+/**
+ * Loads string templates, also known as inline templates.
+ *
+ * We only allow strings that begin with a specific comment so that exceptions
+ * are thrown when a template does not exist.
+ *
+ * @see \Drupal\Core\Template\TwigEnvironment::renderInline()
+ * @see \Drupal\Core\Render\Element\InlineTemplate
+ */
+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);
+    }
+  }
+
 }
 
