我想我没有使用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上,我没有抓住它并且我的脚本停止了。
我的错误在哪里?
答案 0 :(得分:1)
您正在使用限定名称,导致其解析当前命名空间,即Imagine\Exception\Exception
将解析为\CurrentNamespace\Imagine\Exception\Exception
,并且由于这不存在,您可以使用#{1}}。没有抓到任何东西。
使用导入的命名空间,即Exception
,即Exception\Exception
,它将解析为\Imagine\Exception\Exception
,或使用正确的完全限定名称,即以a开头的名称\
,即\Imagine\Exception\Exception
。
另请参阅 PHP Manual > Language Reference > Namespaces > Using namespaces: Basics