我有这样的错误:捕获可变例外
[星期三年07月25 15点48分09秒2012] [错误] [客户端50.xxx.xxx.xxx] PHP致命错误:调用一个成员函数的getSource()的非对象在/var/www/magento/app/code/core/Mage/Catalog/Model/Product.php线1389
在此功能上:
/**
* Get attribute text by its code
*
* @param $attributeCode Code of the attribute
* @return string
*/
public function getAttributeText($attributeCode)
{
return $this->getResource()
->getAttribute($attributeCode)
->getSource()
->getOptionText($this->getData($attributeCode));
}
而我想在发生错误时记录$ attributeCode的值。所以我改变了功能,这一点:
public function getAttributeText($attributeCode)
{
try {
return $this->getResource()
->getAttribute($attributeCode)
->getSource()
->getOptionText($this->getData($attributeCode));
} catch (Exception $e) {
Mage::log($attributeCode);
throw($e);
}
}
...并重新启动Apache,但没有在server.log中显示出来。如果我将throw($ e)注释掉,异常仍然会抛出。
./lib/Zend/Rest/Server.php has set_exception_handler(array($ this,“fault”));
但请告诉我一旦你设置了某个地方,php不会忽略所有的手动异常处理。因为那会很疯狂。
任何想法如何才能捕获$ attributeCode只有当异常发生?
Php无法捕获try catch块中的致命错误。您可以在set_exception_handler函数中为uncatch异常定义php行为,因此如果您想要“php可以忽略所有异常”,则此更改会影响全局范围。 – mrok 2012-07-26 22:37:06