Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Cannot catch exception
  • Hello

    I'm using fuel 1.2.
    I can't catch an exception from a core class.
    In a model, I wrote 

    public function myHandler($e)
    {
    Log::debug('myHandler');
    }
    public function test()
    {
    set_exception_handler(array($this, 'myHandler')); // disables Fuel exception handler
    try
    {
    $this->redis->evalsha('sqdjsklj', 0);  // this line generates an exception
    }
    catch(Exception $e)
    {
    Log::debug('catch');  // is never invoked
    }
    restore_error_handler(); // restores Fuel exception handler
    }

    but the code in the catch is never executed, and I see the error message in the browser output. 
    Is there a way to ensure the code in the catch is executed when an exception occurs?
  • Are you sure, that this is the right syntax for set_exception_handler function?
    http://php.net/manual/en/function.set-exception-handler.php

    I would also check the log file for further information.
  • Nothing in the log file
    And yes, the syntax is right for set_error_handler(). When I write something like 
    set_exception_handler('myHandler');

    I've got an error message telling that 'myHandler' is not a valid exception handler. I don't know why there is a difference with this doc, maybe something related to the PHP version? I'm using PHP 5.3.8.
    I found this syntax in the comment of the page you referred.

    Some precisions as my initial post is a bit confusing: 

    • I started without the set_exception_handler, and the catch was never called, and after digging I found that Fuel defines a gloal exception handler ; that's why I tried this;
    • I the code in posted above, 'myHandler' is not invoked; the exception is thrown and appearsin the browser output. Setting the exception handler as I did it just changed the presentation of the stacktrace.


  • What is the exact Exception being thrown? And are you sure it's not a PHP error (which can't be caught)?

    Quite a few things have changed since v1.2, so you might want to upgrade to a supported version first.
  • It's a RedisException, that extends FuelException, and is defined in the core/redis.php file I took from Redis 1.4 and inserted in Fuel 1.2 install.

    Is the upgrade from 1.2 to 1.4 painful? Where could I find hints about this upgrade?
  • Best port of call would be the changelogs: https://github.com/fuel/core/wiki

    Pay particular attention to the sections about deprecated or removed code, and changes impacting backward compatibility.

    And I would go to 1.5, since that was released this weekend.

    You should be able to catch that without problems. If you backported it, check fuel/core/bootstrap.php, it could be that the class(es) are not defined, which means they are not aliased to global, and \RedisException does not exist.
  • Thanks Harro!
    The RedisException is defined in bootstrap... I guess I will have to upgrade my Fuel release from 1.2.1 to 1.5.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion