Php 如果存在QueryException,如何继续循环?

Php 如果存在QueryException,如何继续循环?,php,laravel,laravel-5,foreach,Php,Laravel,Laravel 5,Foreach,我想储存一些产品和模型。我使用curl获取这些数据,有时会发生意外错误。但我想在发生这种情况时继续foreach循环。我该怎么做 private function storeAllModels() { foreach ($this->models as $model_bundle) { foreach ($model_bundle as $model) { $source = $this->getSourceWithCurl($this

我想储存一些产品和模型。我使用curl获取这些数据,有时会发生意外错误。但我想在发生这种情况时继续foreach循环。我该怎么做

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;
            }

        }
    }
}

我使用了try-catch语句,但仍有错误中断foreach循环

try with-global-exception类,它将捕获所有类型的错误

    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 (\Exception $e) {
                array_push($this->errors, $model);
                continue;
            }

        }
    }
}

尝试使用全局异常类,该类将捕获所有类型的错误

    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 (\Exception $e) {
                array_push($this->errors, $model);
                continue;
            }

        }
    }
}

错误说明了什么?列未找到它说明了什么。我想模式有问题。有时它会给我一个错误,你可以通过检查表是否有特定的列来解决这个问题,得到如下列:
$columns=Schema::getColumnListing($table)
但这只是最后一种方法,如果您没有找到答案,我真的不知道如何不打破looptry
}捕获(\Exception$e){
错误说明了什么?列未找到它说明了什么。我猜模式存在问题。有时它会给我错误。您可以通过检查表中是否有特定列来解决此问题,您会得到如下列:
$columns=Schema::getColumnListing($table)
但这只是最后一种方法,如果您没有找到答案,我真的不知道如何不打破循环try
}捕获(\Exception$e){
但我不明白这背后的登录名?QueryException类继承自Exception类..为什么它不起作用?您可以根据具体情况捕获特定的错误集,例如,假设您正在将文件上载到服务器,同时将其保存到数据库,在这种情况下,我们无法验证这取决于它可能会导致什么样的错误,有时它可能会由于权限问题等原因导致文件处理错误。或者它可能会出现与数据库相关的错误,这取决于您必须决定使用哪个类的情况,我想这会影响性能。但是我不理解这背后的登录名?QueryException类继承自ExceppION类..为什么它不起作用?您可以根据具体情况捕获特定的错误集,例如,假设您正在将文件上载到服务器,同时将其保存到数据库,在这种情况下,我们无法确定它可能导致什么类型的错误,有时它会导致文件处理错误权限问题等,或者可能会出现与数据库相关的错误,这取决于您必须决定使用哪个类的情况,我想这会影响性能。。