diff --git a/src/Illuminate/View/View.php b/src/Illuminate/View/View.php index c7aa1df5d319..f5e82c2605a8 100755 --- a/src/Illuminate/View/View.php +++ b/src/Illuminate/View/View.php @@ -390,14 +390,18 @@ public function __call($method, $parameters) throw new BadMethodCallException("Method [$method] does not exist on view."); } - /** - * Get the string contents of the view. - * - * @return string - */ - public function __toString() - { - return $this->render(); - } + /** + * Get the string contents of the view. + * + * @return string + */ + public function __toString() + { + try { + return $this->render(); + } catch (\Exception $e) { + return $e->getMessage(); + } + } } diff --git a/tests/View/ViewTest.php b/tests/View/ViewTest.php index 0904c4a0fea9..96baef4247fe 100755 --- a/tests/View/ViewTest.php +++ b/tests/View/ViewTest.php @@ -203,6 +203,14 @@ public function testWithErrors() } + public function testViewExceptionHandling() + { + $view = $this->getView(); + + $this->assertEquals('Method Mockery_0_Illuminate_View_Factory::incrementRender() does not exist on this mock object', (string) $view); + } + + protected function getView() { return new View(