doumu1951 2014-03-11 12:30
浏览 48
已采纳

亚马逊S3 SDK for PHP中的异常处理

I recently migrated from age old amazon AWS SDK (v1.6.2) for PHP to the latest one. One thing I completely missed was Exception handling.

My first code.

$result = $this->S3Client->putObject($options);
if (!empty($result)) {
    return !0;
}

But if upload fails, then it will throw an exception which will crash my PHP. So, I added exception handling next.

try {
    $result = $this->S3Client->putObject($options);
    return !0;
} catch(Exception $e) {
    log_message($e->message);
    return !1;
}

However, it seems that $e->message is protected.

Question: How can I get the error so that I can root cause what happened with the upload, once I move to production environment?

  • 写回答

1条回答 默认 最新

  • dpr77335 2014-03-11 12:37
    关注

    Try using:

    log_message($e->getMessage());
    

    More info here and here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效