Index: template/defaulttags.py
===================================================================
--- template/defaulttags.py	(revision 7535)
+++ template/defaulttags.py	(working copy)
@@ -57,6 +57,13 @@
         output.append(pformat(sys.modules))
         return ''.join(output)
 
+class ExceptionNode(Node):
+    def __init__(self, exception):
+        self.exception = exception
+
+    def render(self, context):
+        raise self.exception
+
 class FilterNode(Node):
     def __init__(self, filter_expr, nodelist):
         self.filter_expr, self.nodelist = filter_expr, nodelist
@@ -640,10 +647,16 @@
     if len(bits) != 3:
         raise TemplateSyntaxError, "%r takes two arguments" % bits[0]
     end_tag = 'end' + bits[0]
-    nodelist_true = parser.parse(('else', end_tag))
+    try:
+        nodelist_true = parser.parse(('else', end_tag))
+    except Exception, e:
+        nodelist_true = NodeList([ExceptionNode(e)])
     token = parser.next_token()
     if token.contents == 'else':
-        nodelist_false = parser.parse((end_tag,))
+        try:
+            nodelist_false = parser.parse((end_tag,))
+        except Exception, e:
+            nodelist_false = NodeList([ExceptionNode(e)])
         parser.delete_first_token()
     else:
         nodelist_false = NodeList()
@@ -761,10 +774,16 @@
             boolvars.append((True, parser.compile_filter(boolvar)))
         else:
             boolvars.append((False, parser.compile_filter(boolpair)))
-    nodelist_true = parser.parse(('else', 'endif'))
+    try:
+        nodelist_true = parser.parse(('else', 'endif'))
+    except Exception, e:
+        nodelist_true = NodeList([ExceptionNode(e)])
     token = parser.next_token()
     if token.contents == 'else':
-        nodelist_false = parser.parse(('endif',))
+        try:
+            nodelist_false = parser.parse(('endif',))
+        except Exception, e:
+            nodelist_false = NodeList([ExceptionNode(e)])
         parser.delete_first_token()
     else:
         nodelist_false = NodeList()
