为什么我无法在Azure PHP sdk上捕获ServiceException?

时间:2017-10-03 14:22:08

标签: php azure blob

我试图找出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

1 个答案:

答案 0 :(得分:2)

您可能没有使用完全限定的异常类名称。尝试:

//...
} catch (\MicrosoftAzure\Storage\Common\Exceptions\ServiceException $e) {
//...
}