I'm using Zend DB Adapter class from Zend Framework in a non-zend web application (don't need the whole framework). I need to intercept/handle all DB exceptions to create a custom error page. By default in case of any errors the adapter shows its own plain page with error message like "PDO Exception...". Is there a way to customize this error output without having "try...except" operators around every single database request? Thank you.
+2
A:
you need the try/catch constrcut to achieve what you want as zend hierarchically extends all exceptions to all sub-packages you can easily decide where to catch which exceptions. the followiung code will catch all exceptions which are somewhere in the package Zend_Db_Adapter.
try {
// my code which may throw exceptions
} catch( Zend_Db_Adapter_Exception $e ) {
echo '<h1 style="color: red;">Exception information</h1> <pre>';
print_r($e);
echo '</pre>';
}
ie. here you can see the methods available on any exception object.
zolex
2010-09-25 00:33:39