Try this, it works for me.

class X_Error_Handler
{
    public static function handle($errno, $errstr, $errfile, $errline)
    {
        //this allows error suppression in 3rd party code to work
        if (!error_reporting()) return;

        throw new X_RuntimeException($errstr . " in $errfile:$errline",
$errno);
    }
    
    public static function set()
    {
        set_error_handler(array(__CLASS__, 'handle'));
    }
}

Then you call X_Error_Handler::set() in your bootstrap and built in php
errors will bubble up to error controller as exceptions.
Bear in mind there are some limitation to it, like fatal errors cannot be
handled this way and not everything can be captured in the error controller.
You need a try-catch block around your whole dispatch loop to catch errors
in plugins etc.

Regards
Karol


umpirsky wrote:
> 
> I'm trying to do this with set_error_handler(), my will is to trigger
> Error
> controller and catch this as application error, since I want to log all
> errors in one place - Error controller.
> I tried with setting error handler in bootstrap to function in index.php
> and
> that function calls error controller statically, but no success. There
> must
> be some easy way to do this.
> 
> Anyone know?
> 
> Regards,
> Saša Stamenković
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Turn-PHP-errors-warnings-notices-into-exceptions-tp25591556p25643507.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to