immobiliare / ApnsPHP

ApnsPHP: Apple Push Notification & Feedback Provider
BSD 3-Clause "New" or "Revised" License
1.44k stars 452 forks source link

Why if not connect sending «uncaught exception» and script die? #98

Open Krispian opened 9 years ago

Krispian commented 9 years ago

Hello! Im use your cool lib but I have a question: Why in Absrtact class, if not connect to server sending uncaught exception? Why not wrap it in try...catch.. block that script not died? if (!$this->_hSocket) { throw new ApnsPHP_Exception( "Unable to connect to '{$sURL}': {$sError} ({$nError})" ); }

kongkannika commented 9 years ago

you can use ApnsPHP_Exception to catch the exception

    try {
        $push->connect();
    } catch (ApnsPHP_Exception $e) {
        //log($e->getTraceAsString(), LOG_ERR);
    } catch (Exception $e) {
        //log($e->getTraceAsString(), LOG_ERR);
    }
kanadgodse commented 8 years ago

Even I'm facing a similar issue. I am using this library in a cron job and if there are any exceptions thrown, then the code just exits! This stalls processing of other items in the loop resulting in same push notifications being sent multiple times cause they all end up getting stuck on the one errornous device token. I will have to now sit and re write all thrown exceptions to have catch statements. At least the library should've had an option to log the exceptions instead of just throwing them without catching them.