In the file: app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Datetime.php, within the render() method, it seems like the exact same code is being run in both the try and catch blocks. The exception isn't handled at all. I'm curious to know what the reasons (if any) are for writing code like this:

try {
     $data = Mage::app()->getLocale()
         ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format);
} catch (Exception $e) {
     $data = Mage::app()->getLocale()
         ->date($data, Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($format);

To me there's no reason for such code in that specific case.

I can think of reasons where you could do that when dealing with timing out requests.

For example:

  • some code takes a crazy long time to finish
  • you try to do something that depends on the result of this code
  • as the code is not done yet an exception is thrown
  • in your catch block you add some waiting time (sleep) and try again

But in any case this is very bad design and it is bad in terms of performance as exceptions are resource consuming.

The catch block must only be used for exception handling and rollback of unfinished stuff (e.g database rollback)

I didn't check the entire method for the code you mention but whenever I see code like that I tend to think that the code should be refactored and/or a talk with the programmer is needed to understand the reason behind this code as such code may hide bigger problems deeper in the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.