samedi 28 juillet 2018

How to continue to loop if there is QueryException

I want to store some products models. I'm getting these data with curl, sometimes unexpected errors happen. But I want continue to foreach loop when this happened. How can I do that ?

private function storeAllModels()
    {
        foreach ($this->models as $model_bundle) {
            foreach ($model_bundle as $model) {
                $source = $this->getSourceWithCurl($this->base_url . "/" . $model);
                $details = $this->getModelDetails($source);
                if ($details == "error") {
                    array_push($this->errors, $model);
                    continue;
                }
                try {
                    $model = new Product();
                    $model::forceCreate($details);
                } catch (QueryException $e) {
                    array_push($this->errors, $model);
                    continue;
                }

            }
        }
    }

I use try catch statement but still errors breaks foreach loop



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire