【问题标题】:Continue the execution code after a Fatal Error在发生致命错误后继续执行代码
【发布时间】:2011-12-04 20:30:28
【问题描述】:

我使用 imagick 创建 PDF 文件的缩略图,但在某些情况下 imagic 返回致命错误。 我正在寻找一种方法来了解致命错误何时发生。 像这样的:

function MakeThumb($source) {
    if($im = new imagick($source)) {
    //Generate thumbnail
    return($thumb);
    } else {
    return 'no_thumb.png'; // then we will not tray again later.
    }
}

【问题讨论】:

  • 它被称为致命是有原因的。修复错误是适当的操作。

标签: php imagick


【解决方案1】:

你可以这样做

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,你可以让它工作

http://php.net/manual/en/language.exceptions.php

【讨论】:

  • $e 变量是个例外。所以你可以去die ('Thumb did not create: ' . $e->getMessage());,这可以回显'Count not create thumb'的错误
猜你喜欢
  • 2016-12-19
  • 2021-05-24
  • 1970-01-01
  • 2021-09-21
  • 2022-11-25
  • 1970-01-01
  • 2021-10-12
  • 1970-01-01
  • 2021-09-09
相关资源
最近更新 更多