下面是我在函數中的try catch語句。我還沒有使用try catch語句,我想知道如何在try catch語句中返回值,並且應該在try和catch語句之後返回值或在try塊中返回是否正確?嘗試和趕上PHP應該在嘗試塊返回?
function createBucket($bucket_name) {
if ($this->isValidBucketName($bucket_name)) {
if ($this->doesBucketExist($bucket_name)) {
return false;
} else {
try {
$this->s3Client->createBucket(
array(
'Bucket' => $bucket_name,
'ACL' => CannedAcl::PUBLIC_READ
//add more items if required here
));
return true;
} catch (S3Exception $e) {
$this->airbrake->notifyOnException($e);
return false;
}
}
} else {
$this->airbrake->notifyOnError('invalid bucket name');
return false;
}
}
你試過了嗎?這是絕對好 – Eric 2013-02-24 13:34:03