Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This question is over 2 years old, but the OP's observation that some exceptions thrown from an error handler cannot be caught is actually correct:</p> <pre><code>function errorHandler($errno, $errstr, $errfile, $errline) { throw new Exception($errstr); } function exceptionHandler($e) { echo "exceptionHandler: '", $e-&gt;getMessage(), "'\n"; } set_error_handler("errorHandler"); set_exception_handler("exceptionHandler"); // this works as expected $a = $foo; // this does not $a = $foo(); </code></pre> <p>In the last line, there are actually two errors triggered in short succession:</p> <ol> <li><em>"Undefined variable: foo"</em> (E_NOTICE)</li> <li><em>"Function name must be a string"</em> (E_ERROR)</li> </ol> <p>One would expect <code>errorHandler()</code> to catch the E_NOTICE and throw an Exception, which then gets handled by <code>exceptionHandler()</code>. Since <code>exceptionHandler()</code> never returns, execution should stop there.</p> <p>But that's not what happens: The <code>errorHandler()</code> does get called and throws its Exception, but before the <code>exceptionHandler()</code> can react, PHP decides to exit due to the fatal E_ERROR.</p> <p>It's unfortunate, and there's no pretty generic solution that I'm aware of. One thing you could do is to not <code>throw new Exception(...)</code> from your error handler, but directly call <code>exceptionHandler(new Exception(...))</code>. This works as expected, but has the disadvantage that you cannot <code>try .. catch</code> PHP errors anymore.</p> <p><strong>UPDATE 2014-04-30:</strong></p> <p>This has apparently been fixed in PHP 5.5 (or possibly 5.4, I can't test that now). <code>$foo</code> and <code>$foo()</code> now behave the same way, they both produce the output <code>exceptionHandler: 'Undefined variable: foo'</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload