catch an iconv E_NOTICE
am 24.09.2009 15:42:29 von Tom Worster
i have this hack that works up to a point...
function my_err_handler($errno, $errstr, $errfile, $errline) {
if ( preg_match('/iconv/', $errstr) ) {
throw new Exception('iconv error');
} else {
// ? how to invoke default error handler ?
}
}
set_error_handler("my_err_handler", E_NOTICE);
try {
$s = iconv($enc1, $enc2, $s);
} catch (Exception $e) {
// deal with the failed conversion
}
but i'd like proceed with default error handling in the branch with the
question marks. how can i do that?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: catch an iconv E_NOTICE
am 24.09.2009 16:30:03 von David Otton
2009/9/24 Tom Worster :
> 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:
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.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: catch an iconv E_NOTICE
am 24.09.2009 17:25:06 von Tommy Pham
----- Original Message ----
> From: Tom Worster
> To: PHP General List
> Sent: Thursday, September 24, 2009 6:42:29 AM
> Subject: [PHP] catch an iconv E_NOTICE
>
> i have this hack that works up to a point...
>
> function my_err_handler($errno, $errstr, $errfile, $errline) {
> if ( preg_match('/iconv/', $errstr) ) {
> throw new Exception('iconv error');
> } else {
> // ? how to invoke default error handler ?
http://www.php.net/manual/en/function.restore-error-handler. php
> }
> }
> set_error_handler("my_err_handler", E_NOTICE);
>
> try {
> $s = iconv($enc1, $enc2, $s);
> } catch (Exception $e) {
> // deal with the failed conversion
> }
>
> but i'd like proceed with default error handling in the branch with the
> question marks. how can i do that?
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: catch an iconv E_NOTICE
am 24.09.2009 18:41:05 von Tom Worster
On 9/24/09 10:30 AM, "David Otton" wrote:
> 2009/9/24 Tom Worster :
>
>> 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:
>
>
> 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