Zen Cart Logo
Forums / Contribution-Writing Guidelines / how to catch the $db->Execute($sql) exception?

how to catch the $db->Execute($sql) exception?

Views: 2,468

Results 1 to 2 of 2
25 Jan 2011, 7:04 AM
#1
cindy2010 avatar

cindy2010

Zen Follower

Join Date:
Apr 2010
Posts:
100
Plugin Contributions:
0

how to catch the $db->Execute($sql) exception?

I put a try and catch block around $db->Execute($sql), but when there is database exceptions (such as 1062 Duplicate primary key error), the error will simply be printed out on the page (to be exact, on a totally white page: so all other parts of the code is not executed).

Does anyone have any idea of it? What I want to do is to be able to catch all the exceptions in $db->Execute($sql) call.

Thanks!

25 Jan 2011, 10:52 AM
#2
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,878
Plugin Contributions:
3

Re: how to catch the $db->Execute($sql) exception?

The reason the try/catch fails is that all mysql function call errors are suppressed using the @prepend.

You might want to look at the set_error method in the query factory which processes any errors.