Magento Forum

   
Error handling
 
mateis
Jr. Member
 
Total Posts:  24
Joined:  2008-06-09
 

I think error handling is not very good in magento. For instance, in Mage_Core_Model_Layout , the method createBlock contains the following code :

try {
            $block 
$this->_getBlockInstance($type$attributes);
        
catch (Exception $e{
            
return false;
        
}

This has the effect that any exception generated from any code that runs inside one of the blocks created by me (or any code path that is called from my block - this can be models , helpers, anything actually) will be caught by this exception handler, and the method will simply return false, without any knowledge of what went wrong. Most of the times I got a blank page. Until i found this code and modified it with

try {
            $block 
$this->_getBlockInstance($type$attributes);
        
catch (Exception $e{
           
echo $e->getMessage();
            return 
false;
        
}
to be able to see what I did wrong.

Also I find it frustrating that if I have an error in one of my XML files, I get automaticaly a redirect to an “error” page in which it tells me that “headers were already sent ..”. This is of no use to me, and besides turning off javascript which i don’t want, i don’t have any other solution for seeing the error messages except telnet’ing on port 80 and making a manual request to see what i get.
I think error handling should get a second look because it can really be improved. At least maybe provide a second entry point besides index.php (as in symfony for example) which would have debugging messages enabled and not have this kind of ‘sweep under the floor’ atitude towards errors.

 
Magento Community Magento Community
Magento Community
Magento Community
 
bozmac
Jr. Member
 
Total Posts:  18
Joined:  2008-06-17
 

good point. that’s the worst kind of error handling.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brandlive_br
Guru
 
Avatar
Total Posts:  653
Joined:  2008-05-19
Buenos Aires, Argentina
 

That’s correct.
I think that I use:

try {
            $block 
$this->_getBlockInstance($type$attributes);
        
catch (Exception $e{
           error_log
("[" date("Y-m-d h:i:s") . "] " $e->getMessage() . "\n"3"/path/to/uour/log.log");
            return 
false;
        
}

With this simple change, you can log your errors, but you don’t show that message to clients.

 
Magento Community Magento Community
Magento Community
Magento Community
 
xinhaozheng
Sr. Member
 
Total Posts:  107
Joined:  2009-03-09
 

anyone got a way to temp recover error handler to php default or temp stop magento error handler.

 
Magento Community Magento Community
Magento Community
Magento Community
 
borje
Member
 
Total Posts:  40
Joined:  2010-10-21
 

I’d like to have the following code for createBlock:

try {
    $block 
$this->_getBlockInstance($type$attributes);
catch (Exception $e{
    
if(Mage::getIsDeveloperMode())
    
{
        
echo $e->getMessage();
        
// Or even throw $e would work for me
    
}
    Mage
::logException($e);
    return 
false;
}

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top