4

An exception is thrown in my shutdown function and not caught within a try/catch block, for example:

<?php

set_exception_handler(function($e){
    echo "exception handled"; // not echoed
});

register_shutdown_function(function(){
    throw new Exception("test"); // this should be caught by the exception handler above, but it doesn't
});

Live run.

Running the above code gives:

Fatal error: Uncaught exception 'Exception' with message 'test'

However PHP Manual claims:

set_exception_handler sets the default exception handler if an exception is not caught within a try/catch block. Execution will stop after the exception_handler is called.

Why does exception_handler not catch the exception thrown?

Pacerier
  • 86,231
  • 106
  • 366
  • 634

1 Answers1

0

Because it is beyond the scope...

http://www.php.net/manual/en/function.register-shutdown-function.php

Registers a callback to be executed after script execution finishes or exit() is called.

It must be stripping down your handlers as the execution of your script has finished and is in fact shutting down.

user2723025
  • 477
  • 4
  • 16
  • However, what you claim is not mentioned at all by the docs. The docs for http://php.net/set_exception_handler does not state that it's out of scope for the use case above. – Pacerier Mar 30 '15 at 13:53