다음은 기능에서 try try catch 문입니다. try catch 문을 많이 사용하지 않았습니다. try catch 문에서 값을 반환하는 방법을 알고 싶었습니다. 문을 catch하거나 try 블록을 반환 한 후 값을 반환해야합니까?시도하고 PHP에서 catch 내가 try 블록에 반환해야합니까?
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