1

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?

josepmra
  • 617
  • 9
  • 25
  • The first example is flawed, as the namespace provided for the exception handler is wrong -- you provided "SecureDraw\Fun::exception_handler" when it should be "App\Fun::exception_handler". Within ZF2, we don't register an exception handler by default; we simply have a try/catch block in relevant listeners. This may be blocking your exception handlers, as technically the exceptions are handled. – weierophinney Oct 29 '12 at 16:50
  • This is a write error, now already is solved. – josepmra Oct 29 '12 at 20:21
  • I am having the same issue. I'm trying to catch my exceptions in the onDispatch method of my abstract controller so I'm not repeating every one of my actions with try/catches around db statements all to just return the same thing. Now that @josepmra corrected his mistake in his example, can you offer any more insight @weierophinney? – four43 Jun 06 '13 at 20:35

1 Answers1

0

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

Lucian Depold
  • 1,999
  • 2
  • 14
  • 25