1

I found different cases to use Magento throw exception, I want to know what is the difference between (Mage_Core_Exception $e) and (Exception $e) ? I found What's the preferred way of throwing exceptions in Magento? answer, but it's not precise for me. Is Mage::throwException is the correct one and that we should use ?

1

This is just PHP type hinting ... the one expects $e to be element of class Exception, the other one expects Mage_Core_Exception.

Since class Mage_Core_Exception extends Exception the only "differences" are three changed methods.

For Mage::throwException() see app/Mage.php. At the end it is throws a new exception of class Mage_Core_Exception (thats child of PHPs Exception).

public static function throwException($message, $messageStorage = null)
{
    if ($messageStorage && ($storage = self::getSingleton($messageStorage))) {
        $storage->addError($message);
    }
    throw new Mage_Core_Exception($message);
}
  • The three changed methods link doesn't work, however your answer does not answer my question, I want to know exactly the difference between, according to you answer you mean that (Exception $e) and (Mage_Core_Exception $e) is the same thing and there no difference ? – PЯINCƏ Jul 31 '17 at 21:01
  • Yes, exactly. Only the behavior of the (now correctly linked) mehtods changed. So go for Mage_Core_Exception and Mage::throwException() :) – sv3n Jul 31 '17 at 21:03
  • 1
    I'll downvote your answer because you you gave me a link that not working :) – PЯINCƏ Jul 31 '17 at 21:04
  • @Prince it's okay if you'd accept at least :P – sv3n Aug 4 '17 at 0:32
  • I accept on condition if you give a few points :) – PЯINCƏ Aug 4 '17 at 18:36

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.