我试图找出blob是否存在。当blob不存在时,我的try-catch
与Azure ServiceException
根本没有被捕获。我尝试按照here中的步骤进行操作。
public function checkBlobExists($path) {
$container = config('azure.storage.container');
$blobClient = ServicesBuilder::getInstance()->createBlobService(config('azure.storage.connection_string'));
try {
$blob = $blobClient->getBlob($container, $path);
return true;
} catch (ServiceException $e) {
return false;
}
return false;
}
这是一些错误堆栈:
ServiceException in ServiceRestProxy.php line 491:
Fail:
Code: 404
Value: The specified blob does not exist.
details (if any): .
in ServiceRestProxy.php line 491
at ServiceRestProxy::throwIfError(object(Response), array('200', '206')) in ServiceRestProxy.php line 409
at ServiceRestProxy->MicrosoftAzure\Storage\Common\Internal\{closure}(object(ClientException)) in Promise.php line 203
答案 0 :(得分:2)
您可能没有使用完全限定的异常类名称。尝试:
//...
} catch (\MicrosoftAzure\Storage\Common\Exceptions\ServiceException $e) {
//...
}