Re: catch an iconv E_NOTICE

From: Date: Thu, 24 Sep 2009 16:41:05 +0000
Subject: Re: catch an iconv E_NOTICE
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-298324@lists.php.net to get a copy of this message
On 9/24/09 10:30 AM, "David Otton" <phpmail@jawbone.freeserve.co.uk> wrote: > 2009/9/24 Tom Worster <fsb@thefsb.org>: > >> 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.

« previous php.general (#298324) next »