-- iceangel89 <[email protected]> wrote
(on Tuesday, 02 June 2009, 05:18 AM -0700):
>
> sometimes when exception happen, i would like more info ... like when DB
> queries fail ... the stack trace don't seem to helpful to me. i think the
> full SQL that failed shld be outputted ... don't u think?
No, actually. Exception messages should usually be brief and only
indicate the minimal amount of information to determine where in the
application code an error occurred.
DB errors based on bad SQL are the sorts of things you should catch
during development. As such, you may want to add a case in your
ErrorController for database exceptions that pulls information from
Zend_Db_Profiler:
switch ($errors->type) {
// ... handle missing controller/action types ...
default:
$e = $errors->exception;
if (($e instanceof Zend_Db_Exception)
|| ($e instanceof PDOException)
){
$adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
$profiler = $adapter->getProfiler();
$message = 'A database error occurred: ' . $e->getMessage .
"\n"
. 'Last SQL executed: '
. $profiler->getLastQueryProfile()->getQuery();
} else {
// handle other exception types here
}
break;
}
Obviously, don't display error messages such as this during production.
:)
--
Matthew Weier O'Phinney
Project Lead | [email protected]
Zend Framework | http://framework.zend.com/