cloudfiles API:当容器不存在时,get_container 未捕获异常
我使用rackspace cloudfiles API 动态上传文件,它需要做的第一件事是检查容器是否存在,如果不存在,则创建它。
所以我写了以下内容:
if($container = $conn->get_container('my_container')){
echo 'yay';
} else {
$container = $conn->create_container('my_container');
$container->make_public();
}
但是如果容器不存在 get_container
会抛出异常,因此我会收到致命错误。完成我在这里尝试做的事情的最佳方法是什么?
I'm using the rackspace cloudfiles API to upload files on the fly and the first thing it needs to do is check whether the container exists and if not, create it.
So I write the following:
if($container = $conn->get_container('my_container')){
echo 'yay';
} else {
$container = $conn->create_container('my_container');
$container->make_public();
}
But if the container doesn't exist get_container
throws an exception and so I get a fatal error. What's the best way to do what I'm trying to do here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您也可能会遇到显式异常:
如果您遇到网络问题或相关问题,这不会失败。
you could expect an explicit exception also:
this will not fail if you have networking problems or something related.