当提要输入错误时,为什么我在 Zend Feed 中没有得到预期的异常?
基本上,我们在这里提供了这个模块,供希望在其页面上的其他位置包含提要的用户使用。 我工作得很好,没有流汗。 问题是,每当用户错误处理手上的 feed 链接时,我们就必须手动删除该模块,因为 Zend Feed 会像任何致命错误一样崩溃并烧毁整个页面。 代码块,人们会期望诸如.. ..之类的代码块
try { // Test piece straight off the Zend tutorial
$slashdotRss = Zend_Feed::import('http://rss.slashdot.org/Slashdot/slashdot');
} catch (Zend_Feed_Exception $e) {
// feed import failed
echo "Exception caught importing feed: {$e->getMessage()}\n";
exit;
}
通常,如果我输入“httn://rss.grrllarrrllll.aarrg/Slashdot/slashdot”并说出“404”或“什么”之类的 会起作用。该死”。 不,它死了。 它崩溃并死亡。 它崩溃、燃烧、死亡,完全忽略了所有快乐的 trycatch 方法。
所以基本上,我们是否必须在 feedfetch 上编写我们的内容,或者是否有任何简单的补救措施来解决 Zend 的错误?
添加日志:
exception 'Zend_Http_Client_Adapter_Exception' with message 'Unable to Connect to tcp://www.barglllrragglll:80. Error #10946: ' in /library/Zend/Http/Client/Adapter/Socket.php:148
#0 /library/Zend/Http/Client.php(827): Zend_Http_Client_Adapter_Socket->connect('www.barglllrragglll...', 80, false)
#1 /library/Zend/Feed.php(284): Zend_Http_Client->request()
...... Trace etc ....
Basically, we have this here module that we offer to our users that want to include a feed from elsewhere on their pages. I works great, no sweat. The problem is that whenever users mishandle the feed link on their hands we have to manually remove the module from existence because Zend Feed crashes and burns the entire page just like any fatal error. Normally, one would expect that a code block such as..
try { // Test piece straight off the Zend tutorial
$slashdotRss = Zend_Feed::import('http://rss.slashdot.org/Slashdot/slashdot');
} catch (Zend_Feed_Exception $e) {
// feed import failed
echo "Exception caught importing feed: {$e->getMessage()}\n";
exit;
}
.. would BEHAVE if I were to enter 'httn://rss.grrllarrrlll.aarrg/Slashdot/slashdot' and say something along the lines of "404" or "What the shit". No. It dies. It crashes and dies. It crashes and burns and dies, completely ignoring all that happy trycatch methology right there.
So basically, do we have to write our on feedfetch or is there any simple remedy to Zend's slip?
Added log:
exception 'Zend_Http_Client_Adapter_Exception' with message 'Unable to Connect to tcp://www.barglllrragglll:80. Error #10946: ' in /library/Zend/Http/Client/Adapter/Socket.php:148
#0 /library/Zend/Http/Client.php(827): Zend_Http_Client_Adapter_Socket->connect('www.barglllrragglll...', 80, false)
#1 /library/Zend/Feed.php(284): Zend_Http_Client->request()
...... Trace etc ....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嘿,你没有捕获正确的异常类型尝试捕获
或同时出现:
顺便说一句,它有一个 toString 方法,因此您只需 echo $e 即可,无需 getMessages。
Hey, you are not catching the right exception type try to catch
or all at once:
btw it has a toString method so you can just echo $e no need to getMessages.
怎么样
$file = file("http://rss.grrrrrrrrl... ”);
$rss = Zend_Feed::importString($file);
?
How about something along the lines of
$file = file("http://rss.grrrrrrrl...");
$rss = Zend_Feed::importString($file);
?
只是出于好奇,您是否尝试捕获其他类型的异常? 即,不仅仅是
Zend_Feed_Exception
?也许,如果在“获取”阶段出现某种 404 错误,它会抛出另一个异常? (因为依赖另一个组件,比如
Zend_Http_Client
?)另外,您是否检查了
error_reporting
级别,以确保会报告错误? 如果display_errors
为Off
,也许在某个日志文件中?顺便说一句,这并不是您问题的真正答案,但是
Zend_Feed
有一些缺点(例如根据提要的格式返回不同类型的数据 - 例如 RSS 与 ATOM)< /em>.从 Zend Framework 1.9 开始(目前,它仅作为预览版或 alpha 版本提供,因此不要在生产中使用它!),将会有一个
Zend_Feed_Reader
组件,这在使用 RSS 和 ATOM Feed 时应该更有用。有关详细信息,请参阅
添加日志后编辑
对于
Zend_Feed
,Feed本身没有问题,因此不会抛出Zend_Feed
代码>相关异常。您这里遇到的问题是另一个问题,例如错误的 URL:它无法获取数据,并且无法分析它; 它解释了为什么异常与
Zend_Feed
无关,而是与Zend_Http_Client
相关。您可能想添加一些其他异常处理代码; 像这样:
这样:
Just out of curiosity, did you try catching other kinds of exception ? ie, not only
Zend_Feed_Exception
?Maybe, if there is some kind of 404 error during the "fetching" phase, it throws another exception ? (Because of relying on another component, like
Zend_Http_Client
? )Also, did you check your
error_reporting
level, to be sure errors would be reported ? Maybe in some log file somewhere, ifdisplay_errors
isOff
?As a sidenot, and not really an answer to your question, but
Zend_Feed
has some drawbacks (like returning different kind of data depending on the feed's format -- RSS vs ATOM, for instance).Starting with Zend Framework 1.9 (right now, it's only available as a preview or alpha version, so don't using it in production !), there will be a
Zend_Feed_Reader
component, which should be more useful when consumming both RSS and ATOM Feeds.For more informations, see
Edit after you added the log
For
Zend_Feed
, there is no problem with the Feed itself, so it doesn't throw aZend_Feed
-related Exception.The problem you have here is another one, like wrong URL : it fails getting the data, and not analysing it ; it explains why the exception is not
Zend_Feed
-related, butZend_Http_Client
-related.You might want to add some other exception-handling-code ; something like this :
This way :