Re: catch an iconv E_NOTICE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/24/09 10:30 AM, "David Otton" <phpmail@xxxxxxxxxxxxxxxxxxxxxxx> wrote:

> 2009/9/24 Tom Worster <fsb@xxxxxxxxxx>:
> 
>> but i'd like proceed with default error handling in the branch with the
>> question marks. how can i do that?
> 
> An error handler that passes through to the previous error handler:
> 
> <?php
> error_reporting(E_ALL);
> 
> function my_error_handler($errno, $errstr, $errfile, $errline) {
>     restore_error_handler();
>     trigger_error($errstr, $errno);
> }
> 
> set_error_handler('my_error_handler', E_ALL);
> 
> trigger_error('TEST', E_USER_ERROR);
> 
> You'll lose the file and line, though, because you're actually raising
> another error with the same message at a new point in the code.

and i'd need to set my error handler back again to catch the next iconv
error:

function my_err_handler($errno, $errstr, $errfile, $errline) {
    if ( preg_match('/iconv/', $errstr) ) {
        throw new Exception('iconv error');
    } else {
        restore_error_handler();
        trigger_error($errstr, $errno);
        set_error_handler('my_error_handler', E_ALL);
    }
}
set_error_handler('my_error_handler', E_ALL);

not lovely. as it stands, my own code writes the error message to the log
file in that place. i'm not sure this is an improvement.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux