How to render template instead of throwing an error?
You can see common patterns for this in Craft's own controllers.

For example in https://github.com/craftcms/cms/blob/master/src/controllers/EntriesController.php#L499-L507, if there's a problem, you can catch the error, set it on a route variable and return null so the original template can display it.

Craft::$app-&gt;getSession()-&gt;setError(Craft::t('app', 'Couldn’t duplicate entry.'));

// Send the original entry back to the template, with any validation errors on the clone
$entry-&gt;addErrors($clone-&gt;getErrors());
Craft::$app-&gt;getUrlManager()-&gt;setRouteParams([
    'entry' =&gt; $entry
]);

return null;


If you don't want to let the original template handle the error, then you should be able to do something like this from your controller:

return $this-&gt;renderTemplate('error', ['error' =&gt; 'Test']);