1

I want to add in some handling for a specific exception

Zend_Db_Statement_Exception' with message 
'SQL ERROR: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

I'd prefer to do string comparison against the exception message somewhere fairly low-level, so that in my application logic, I can simply catch a nice friendly exception like My_Module_Exception_MysqlGoneAway, as opposed to having catch exception clauses with string comparison in them strewn about my application logic.

So in this particular case, the error is being triggered from a load() method, so I could go rewrite Mage_Core_Model_Abstract, overload the load() method and add in the exception handling. But that's not bulletproof, b/c this kind of thing could also be triggered from a collection load or probably other areas of code.

So the other option would be to override lib/Varien/Db/Adapter/Pdo/Mysql.php in app/code/local, and add the exception handling there, but that seems a bit like overkill just to have a nice exception class.

Is there any easier way to do this?

2
  • FYI, Magento now has its own StackExchange site: magento.stackexchange.com Commented Apr 24, 2013 at 17:46
  • Thanks, ya I've been using it. Actually posted this one on SO specifically to gauge the response. There is an ongoing debate within the magento.se as to whether questions should continue to be posted to SO or not. I'm testing out the waters here. Commented Apr 24, 2013 at 23:57

1 Answer 1

1

As you proposed the best solution is to override the MySQL.php adapter in local as this is the file that any MySQL transaction will use. For this error though I would look more into the cause as MySQL gone away could mean that there are bigger problems.

Are you logging in MySQL to see why it is dropping its connection ?

Back to your point though, The adapter class is where all other classes inherit there logic and is the main workhorse for querying the database, There are several instances where you will need to add extra logic to catch the exception. Connection, RawQuery etc.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks James. Yes we've worked to determine the root cause. I know that mysql going away is kind of a larger concern than exception handling. But I also asked this question b/c there have been other cases (outside of mysql errors) where I've wanted to tap into exception handling and the answer to this question will apply closely to those other cases closely.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.