【发布时间】:2017-01-21 00:07:59
【问题描述】:
我正在玩try - catch 块:
<?php
try {
$str = "http://rejstrik-firem.kurzy.cz/73631604";
$domOb = new DOMDocument();
$html = $domOb->loadHTMLFile($str);
$domOb->preserveWhiteSpace = false;
$container = $domOb->getElementById('ormaininfotab');
echo $container; // <========= this is intended error which I want catch
}
catch (Exception $e) {
echo "Exception" . $e->getMessage() . ". File: " . $e->getFile() . ", line: " . $e->getLine();
}
catch (Error $e) {
echo "Error" . $e->getMessage() . ". File: " . $e->getFile() . ", line: " . $e->getLine();
}
?>
我的结果是这样的:
可捕获的致命错误:类 DOMElement 的对象不能 在第 8 行的 /var/www/html/cirkve_ares/test.php 中转换为字符串
为什么这个错误没有被第二次捕获?
【问题讨论】:
-
好的,没人对 try-catch 感兴趣吗?其实对我来说不是这个错误问题。我正在学习 try-catch 在 PHP 中的工作原理。任何机构都可以解释一下,如何捕捉这种类型的错误?为什么没有捕捉到这个错误。
-
刚遇到同样的问题,也是无法转换为字符串导致的E_RECOVERABLE_ERROR....