Why my error handler function can not work?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lian Liming

    Why my error handler function can not work?

    Hi, all
    I want to write my own error handler function in php by using
    "set_error_hand ler()" function. I have made a test for this function but
    found it did not work. My test code is as following:
    <?php
    function myerrorHandler ($errno, $errstr, $errfile, $errline,
    $errcontext)
    {
    switch ($errno)
    {
    case E_USER_WARNING:
    case E_USER_NOTICE:
    case E_WARNING:
    case E_NOTICE:
    case E_CORE_WARNING:
    case E_COMPILE_WARNI NG:
    case E_USER_ERROR:
    case E_ERROR:
    case E_PARSE:
    case E_CORE_ERROR:
    case E_COMPILE_ERROR :
    echo "This is my own error handler
    function\n";
    die();
    }


    }
    set_error_handl er("myerrorHand ler");
    Undefined();
    ?>

    In the code, "Undefined( )" is a function which is not defined in the
    file, so it should produce a error message.
    If my own handler function works, it should print "This is my own error
    handler function". but actually, when my program runs, it gives the
    error report:
    "Fatal error: Call to undefined function: undefined() in
    /var/www/localhost/htdocs/hello.php on line 28"
    which means handler function doesn't work.


    What is wrong? why the function "set_error handler" can not work?
    Thanks for your suggestion!
  • Paul Delannoy

    #2
    Re: Why my error handler function can not work?

    Lian Liming a écrit:[color=blue]
    > Hi, all
    > I want to write my own error handler function in php by using
    > "set_error_hand ler()" function. I have made a test for this function but
    > found it did not work. My test code is as following:[/color]
    .....[color=blue]
    > What is wrong? why the function "set_error handler" can not work?
    > Thanks for your suggestion![/color]

    Read carefully the appropiate doc and ex :


    Comment

    • Jahjah92

      #3
      Re: Why my error handler function can not work?

      The following types of error cannot be managed with this function: E_ERROR,
      E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR and
      E_COMPILE_WARNI NG.


      Comment

      Working...