Index: template/defaulttags.py
===================================================================
--- template/defaulttags.py	(revision 7535)
+++ template/defaulttags.py	(working copy)
@@ -206,7 +206,11 @@
         except VariableDoesNotExist:
             val2 = None
         if (self.negate and val1 != val2) or (not self.negate and val1 == val2):
+            if isinstance(self.nodelist_true, Exception):
+                raise self.nodelist_true
             return self.nodelist_true.render(context)
+        if isinstance(self.nodelist_false, Exception):
+            raise self.nodelist_false
         return self.nodelist_false.render(context)
 
 class IfNode(Node):
@@ -240,7 +244,15 @@
                 except VariableDoesNotExist:
                     value = None
                 if (value and not ifnot) or (ifnot and not value):
+                    # if the nodelist_true branch evaluated to an error
+                    # raise it now
+                    if isinstance(self.nodelist_true, Exception):
+                        raise self.nodelist_true
                     return self.nodelist_true.render(context)
+            # if the nodelist_false brance evaluated to an error
+            # raise it now
+            if isinstance(self.nodelist_false, Exception):
+                raise self.nodelist_false
             return self.nodelist_false.render(context)
         else:
             for ifnot, bool_expr in self.bool_exprs:
@@ -249,7 +261,11 @@
                 except VariableDoesNotExist:
                     value = None
                 if not ((value and not ifnot) or (ifnot and not value)):
+                    if isinstance(self.nodelist_false, Exception):
+                        raise self.nodelist_false
                     return self.nodelist_false.render(context)
+            if isinstance(self.nodelist_true, Exception):
+                raise self.nodelist_true
             return self.nodelist_true.render(context)
 
     class LinkTypes:
@@ -640,10 +656,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 = 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 = e
         parser.delete_first_token()
     else:
         nodelist_false = NodeList()
@@ -761,10 +783,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 = 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 = e
         parser.delete_first_token()
     else:
         nodelist_false = NodeList()
