codernoob8
codernoob8

Reputation: 732

upload a file to s3 php script

I'm trying to upload a file to s3 with php. I copied this code from GitHub, and after subbing in my credentials it seems to work fine. However there's one part in it that frankly I don't understand and seems to be written wrong.

They use two try statements and three catch blocks. Also they're named differently: one uses S3Exception, and the other uses just Exception. From what I understand S3Exception is correct and you should not have more catches than you do tries. Am I correct in my assumption?

Heres the link to the GitHub: link

} catch (S3Exception $e) {
        die('Error:' . $e->getMessage());
} catch (Exception $e) {
    die('Error:' . $e->getMessage());
}

Upvotes: 0

Views: 46

Answers (1)

TofferJ
TofferJ

Reputation: 4784

You can have multiple catch blocks to do different things for different types of exceptions. In your case above, the first block will only catch S3Exceptions. The second block will catch all other types of exceptions.

Upvotes: 1

Related Questions