Re: Intercepting errors (skip)

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

 



sorry i just forgot to print the results. It 's my mistake

----- Original Message ----
From: It Maq <itmaqurfe@xxxxxxxxx>
To: php-general@xxxxxxxxxxxxx
Sent: Thursday, March 13, 2008 11:22:36 AM
Subject: Re:  Intercepting errors

I already read th page of the manual, but i still don't understand a lot of things. Below you will find a simple code that i ade for understanding more about this. In the code i'm triggering an error of type "E_USER_ERROR", so now i'm wondering why it is not considered as E_USER_ERROR in set_error_handler(). And if somebody can suggest an error (something real not just trigger_error) that can be intercepted by set_error_handler(), this will be very useful.here is the code:

<?php
    function error_handler($errno, $errstr, $filename, $lineno, &$context)
    {
        echo $errno. "<br>";
        echo $errstr. "<br>";
        switch($errno) {
            case E_USER_ERROR:
                $str = "";
                $str = "ERROR MESSAGE: ". $errstr;
                $str .= "<br>The application will be stopped just after the following error message:<br>";
                $str.= "<br>File: ". $filename;
                $str.= "<br>Line number: ". $lineno;
                $GLOBALS['toto'] = $str;
                //return $GLOBALS['error'];
                break;    
            case E_USER_WARNING:
                echo "ERROR MESSAGE: ". $errstr;
                echo "<br>The application will continue but there is a warning:<br>";
                echo "<br>File: ". $filename;
                echo "<br>Line number: ". $lineno; 
                break;
            case E_USER_NOTICE:
                echo "ERROR MESSAGE: ". $errstr;
                echo "<br>The application will continue but there is a notice:<br>";
                echo "<br>File: ". $filename;
                echo "<br>Line number: ". $lineno; 
                break;            
        }
    }

echo "Testing set_error_handler<br><br><br>";

error_reporting(E_USER_ERROR|E_USER_WARNING|E_USER_NOTICE);  
set_error_handler('error_handler'); 
ini_set('error_reporting', 0);

trigger_error("The string for testing the error", E_USER_ERROR);


?>



----- Original Message ----
From: Richard Heyes <richardh@xxxxxxxxxxx>
To: It Maq <itmaqurfe@xxxxxxxxx>
Cc: php-general@xxxxxxxxxxxxx
Sent: Thursday, March 13, 2008 11:00:30 AM
Subject: Re:  Intercepting errors

> I'am already using that. When i call trigger_error the function set
> in set_error_handler handles the error. but now i don't know if this
> will handle all the other errors that i don't know about in case they
> happen. Is there anyway to test that?

Read the manual page. I believe it handles all except things like parse 
errors:

"The following error types cannot be handled with a user defined 
function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, 
E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the 
file where set_error_handler() is called."

Oh and Stephane: this is a mailing list. If you want off you can go to 
http://www.php.net.

-- 
Richard Heyes
Employ me:
http://www.phpguru.org/cv





      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 



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






      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs


-- 
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