Exception handling in amazon 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?

Answers


Try using:

log_message($e->getMessage());

More info here and here.


Need Your Help

In facelets, how do I fetch from a HashMap where keys are of DataType Short

jsf-2 facelets el

I am getting an javax.el.ELException: java.lang.Short cannot be cast to java.lang.Long for the following code:

How do I select a row from one table where the value row does not exist in another table?

sql

Let's say I have two identical tables, A and B, with the row "x".