PHP error when rendering a template from __toString() I have a model with the following functions:

public function render() 
{
    $render = craft()-&gt;templates-&gt;render('myplugin/templates/mymodeltemplate');
    return $render;
}

public function __toString()
{
    return $this-&gt;render();
}


Calling __toString() gives me the following error:

Fatal error: Method Craft\MyModel::__toString() must not throw an exception in /projectpath/craft/app/vendor/twig/twig/lib/Twig/Extension/Core.php on line 0

I've found this explanation:

http://php.net/manual/en/migration52.incompatible.php

But I'm not sure how to work around it and accomplish what I'm trying to do...
In PHP, nothing can throw an exception inside of a __toString() method, or else you'll get the error you're seeing.

Not only is that a questionable design decision, it also hides the underlying exception message and stack trace from you.

If you do this, at least you'll be able to log the underlying error and fix that:

public function __toString()
{
    try
    {
        return $this-&gt;render();
    }
    catch (\Exception $e)
    {
        Craft::log('ERROR: '.$e-&gt;getMessage(), LogLevel::Error);
    }
}


Then you can look in your craft/storage/runtime/logs files for [error] to see the exception message.