Search code examples
phpzend-frameworkzend-framework2zend-framework3

How to use exception handling in zend framework php?


try {
    if ($user_session_object['device_type'] == '1') {
        $this->sendNotificationAndroidOne($notificationData);
    }
    throw new Exception("newInner");
    //throw new Exception("newInner");
    if ($user_session_object['device_type'] == '2') {
        $this->sendNotificationIphone($notificationData);
    }
}catch(Exception $ex){
    echo 'Exception occur while send push notification';
    exit;
}

Getting error: Exception' not found in file. Thanks in advance


Solution

  • This is likely a namespace issue (nothing to do with Zend Framework), so you want throw new \Exception("newInner"); and catch(\Exception $ex).

    Otherwise, please add the full error message to your question.