我有這樣的錯誤:捕獲可變例外
[星期三年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