Hi,
I am still looking for the best way how to handle exceptions and errors
within an application based on the Zend Framework.
What I understood is that all Zend Framework components throw an
exception when a problem occured and don't return false or use
trigger_error(). So, when I extend any component I should do the same.
For example if I extend Zend_Db_Table and add a check to the insert()
method that all required fields are filled, then I should also throw an
Zend_Db_Table exception rather than returning false. Please correct me
if I am wrong here.
So, whenever I use a Zend Framework component I should add a try-catch
block around the code that uses the component. For example:
try {
$user->insert($data);
} catch (Zend_Db_Exception $e) {
// handle error
$error = $e->getMessage();
}
Now I could print out the error to the screen or do whatever. Please
correct me if this is bad practice.
What I am not quite sure about is how to handle exceptions which occur
in the controller or dispatcher correctly. The probably need to be
catched in the bootstrap file. Should I then use my view object to print
out a basic error page or is there a better way?
Thanks for your feedback.
Best Regards,
Ralf