Tag Archives: RuntimeException

How to find out the real cause of the boring RuntimeException in ZF2

Nowadays I’m just getting annoying error stack traces from zend framework 2 with a message like:

PHP Fatal error:  Uncaught exception 'ZendViewExceptionRuntimeException' with message 'ZendViewRendererPhpRenderer::render: Unable to render template "error"; resolver could not resolve to a file' in C:worksrcvendorzendframeworkzendframeworklibraryZendViewRendererPhpRenderer.php:451

and naturally the stack trace doesn’t even shows where the real problem happens.

I tried to put the problematic code lines in a try-catch block, but the same happened: uncaught exception. That was really weird, because I tried to catch Exception, which should be every exception’s parent class. Later I found out that since the current file is in a specific namespace, then I have to specify the exact class type of the Exception class. For example:

<?php
namespace SomeName;
class Whatever
{
    try
    {
        //some erroneous code
    }
    catch (Exception $e)
    {
        echo $e;
    }

}

If you would try to catch Exception, then the exception class should be SomeNameException, so that’s why you have to use it like Exception, so php will try to find the class in the root namespace.