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 ?
Add a comment
|
1 Answer
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ƎCommented Jul 31, 2017 at 21:01 -
Yes, exactly. Only the behavior of the (now correctly linked) mehtods changed. So go for
Mage_Core_Exception
andMage::throwException()
:)– sv3nCommented Jul 31, 2017 at 21:03 -
1I'll downvote your answer because you you gave me a link that not working :)– PЯINCƎCommented Jul 31, 2017 at 21:04
-
-