簡體   English   中英

如何處理CakePHP 3中的Imagine異常

[英]How to handle Imagine exception in CakePHP 3

我想我無法使用Imagine libray正確處理異常。

我的代碼是:

use ....
use Imagine\Exception;
....

try {

    $imagine = new Imagine();

    $image = $imagine->open($img_path . DS . "tmpfile." . $extension)
        ->resize(new Box($cwidth, $cheight))
        ->crop(new Point($offsetx, $offsety), new Box(500, 500));

    ...

} catch (Imagine\Exception\Exception $e) {

    die("catch Imagine\Exception\Exception");
    $file = new File($img_path . DS . "tmpfile." . $extension);
    if ($file->exists()) {
        $file->delete();
    }

}

但是在Imagine Exception上,我沒有捕獲到它,並且腳本停止了。

我的錯誤在哪里?

您正在使用限定名稱,導致其相對於當前名稱空間進行解析,即Imagine\\Exception\\Exception將解析為\\CurrentNamespace\\Imagine\\Exception\\Exception ,並且由於該名稱不存在,因此您無法捕獲任何內容。

使用導入的命名空間Exception ,即Exception\\Exception ,它將解析為\\Imagine\\Exception\\Exception ,或者使用適當的完全限定名稱,即以\\開頭的名稱,即\\Imagine\\Exception\\Exception

另請參見PHP手冊>語言參考>命名空間>使用命名空間:基礎

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM