I try use the "set_exception_handler" function for capture my ActionController exceptions.
Inside any view e.g. index.phtml this code works ok, the view show Helloooo.
<?php
namespace App;
echo $this->doctype();
class Fun {
static function exception_handler(\Exception $ex){
echo "Heloooo";
}
function method(){
set_exception_handler('App\Fun::exception_handler');
throw new \Exception('One Exception');
}
}
$f = new Fun();
$f->method();
I don't understand because the same code inside ActionController.php, set_exception_handler() doesn't catch the exception. In this case the view shows the zend exception template with the "One Exception" message.
By the way, the exception stack doesn't show any Warning message, then I assume that set_exception_handler() parameter is well.
namespace App\Controller;
use Zend\....... //All namespaces used
class Fun {
static function exception_handler(\Exception $ex){
echo "Helloooo";
}
function method(){
set_exception_handler('App\Controller\Fun::exception_handler');
throw new \Exception('One Exception');
}
}
$f = new Fun();
$f->method();
class MainController extends AbstractActionController {
//The Controller Code (in this test it doesn't execute).
}
I think Zend Framework uses any technique for catching Controller exceptions in other level. Please does somebody have any idea for do it?
I have to correct my previous post. It seems to be a known bug of ZF. Have a look at this:
http://grokbase.com/t/php/php-bugs/128zn2emcx/php-bug-bug-62985-new-set-exception-handler-doesnt-work-from-command-line