简体   繁体   中英

Best way to catch Zend_DB exceptions in already existing code?

I need to catch Zend_DB exceptions at all places in existing code. What would be the best way and place to do it?

One tedious way I think is to wrap all query code in try catch block but there are so many queries in multiple files. So looking for better and alternate option.

Thanks for your help.

To me, the key is @bububaba's comment to your question: Catch and do what?

The easiest thing to do - so you don't have to dig into db/mapper/model/repository/service controller code - is to just modify your ErrorController to "do something different" when the exception is a Zend_Db_Exception .

But that's really top-level stuff, the last gasp chance to catch the priceless Ming vase before it hits the floor and shatters into a million pieces, probably so far away from the thrown error that you are missing out on more meaningful ways of handling the error. In general, the closer you are to the throw, the better is your knowledge of the context in which that throw occurred, which then informs/guides the best way to handle it (ex: let it bubble up to the top, catch/rethrow, catch/eat, etc.). In that sense, there is probably real benefit in wrapping up smaller chunks into try/catch blocks.

Just thinking out loud. YMMV.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM