Skip to content

Commit

Permalink
bug #2040 handle Throwable (fprochazka)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.x branch.

Discussion
----------

handle Throwable

Related #2041

Commits
-------

99e9d1c handle Throwable
  • Loading branch information
fabpot committed May 30, 2016
2 parents 3dfda00 + 99e9d1c commit dad282f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Twig/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ public function createTemplate($template)
} catch (Exception $e) {
$this->setLoader($current);

throw $e;
} catch (Throwable $e) {
$this->setLoader($current);

throw $e;
}
$this->setLoader($current);
Expand Down
5 changes: 5 additions & 0 deletions lib/Twig/Node/Macro.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public function compile(Twig_Compiler $compiler)
->write("ob_end_clean();\n\n")
->write("throw \$e;\n")
->outdent()
->write("} catch (Throwable \$e) {\n")
->indent()
->write("ob_end_clean();\n\n")
->write("throw \$e;\n")
->outdent()
->write("}\n\n")
->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n")
->outdent()
Expand Down
6 changes: 6 additions & 0 deletions lib/Twig/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ public function render(array $context)
ob_end_clean();
}

throw $e;
} catch (Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}

throw $e;
}

Expand Down
4 changes: 4 additions & 0 deletions test/Twig/Tests/Node/MacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public function getfoo(\$__foo__ = null, \$__bar__ = "Foo"$declaration)
} catch (Exception \$e) {
ob_end_clean();
throw \$e;
} catch (Throwable \$e) {
ob_end_clean();
throw \$e;
}
Expand Down

0 comments on commit dad282f

Please sign in to comment.