我使用imagick创建PDF文件的缩略图,但在某些情况下imagick返回致命错误。我正在寻找一种方法来知道何时发生致命错误。像这样:
function MakeThumb($source) {
if($im = new imagick($source)) {
//Generate thumbnail
return($thumb);
} else {
return 'no_thumb.png'; // then we will not tray again later.
}
}
你可以这样做
function MakeThumb($source) {
try {
//throw exception if can't create file
if(!$im = new imagick($source) {
throw new Exception('Count not create thumb');
}
//ok if got here
return($thumb);
} catch (Exception $e) {
return 'no_thumb.png';
}
}
我还没有测试过,但是通过使用Try Catch
,你可以使它工作