ZendFramework - 如何获取数据库插入错误并停止自动重定向到错误页面?

Trying to insert row, and it fails to insert because of duplicate key found. And throws to error page. But how do i avoid going to error page but simply get the error result? so that i can echo it.

$db->insert("university", $data);
$lastID = $db->lastInsertId();
# when it fails to insert
# how can i run this echo
echo $theCauseOfErrorOnlyDoNotRedirectToError; //??

you should use a try catch block

try {
    $db->insert("university", $data);
    $lastID = $db->lastInsertId();
} catch(Exception $e) {
   // when it fails to insert
   // how can i run this echo
   echo $theCauseOfErrorOnlyDoNotRedirectToError; //??
}

You can review the documentation about exceptions and exception handling.