Search code examples
phpexceptionerror-handlingsymfony1symfony-1.4

Error 500 Page - How do I get the last exception?


If an exception has been thrown, Symfony 1.4 shows by default the "Oops! An Error Occurred" page. I defined an own page (http://symfony-check.org/permalink/customize-the-oops-an-error-occurred-page) and want to inform me by mail if this happens. So is there any chance to get the thrown exception? Something like error_get_last() ?


Solution

  • Thanks for the suggestion @waldek_c!

    Finally I solved the problem with a filter and catch the Exception before the forward to the errorpage. Like this: http://blog.felixdv.com/2008/01/28/exception-catcher-filter-for-symfony/

    This is my Filter:

    class errorHandlingFilter extends sfFilter
    {
    public function execute($filterChain)
    {
        try
        {
            $filterChain->execute();
        }
        catch(Exception $e)
        {
            if($e instanceof sfStopException || $e instanceof sfError404Exception) // common symfony exceptions that are allowed
            {
                throw $e;
            }
            else
            {
                // do errorhandling here
                throw $e;
            }
        }
    }
    }