如何在CakePHP3中处理Imagine异常

如何在CakePHP3中处理Imagine异常,php,cakephp-3.0,php-imagine,Php,Cakephp 3.0,Php Imagine,我想我没有使用Imagine Library正确管理异常 我的代码是: use .... use Imagine\Exception; .... try { $imagine = new Imagine(); $image = $imagine->open($img_path . DS . "tmpfile." . $extension) ->resize(new Box($cwidth, $cheight)) ->crop

我想我没有使用Imagine Library正确管理异常

我的代码是:

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异常中,我没有捕捉到它,脚本也停止了


我的错误在哪里?

您使用的是限定名称,导致它相对于当前名称空间进行解析,即
Imagine\Exception\Exception
将解析为
\CurrentNamespace\Imagine\Exception\Exception
,因为它不存在,所以您无法捕获任何内容

使用导入的命名空间,即
Exception
,即
Exception\Exception
,该命名空间将解析为
\Imagine\Exception\Exception
,或者使用正确的完全限定名,即以
\
开头的名称,即
\Imagine\Exception\Exception


另见

好的,我理解。谢谢