Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-10-2007, 04:51 PM
Junior Member
 
Join Date: Aug 2007
Posts: 1
Question Exception and Error Handling? Best Practice?

Hello,
I'm beginner .... still reading and testing .... reading and testing ... so
I want to ask, what are the best practices in Error and Exception handling in Zend Framework...

I mean ... When the input is incorect and want to show an error message or something ..

For example ...
A blog post is called by its ID argument ... but it's not supplied ...
so what is the best way to show an error message like 'the ID argument is missing' ...

To handle the error in the controller and make a check if there is error when rendering the view script ... or to redirect to errorController (and if so ... how to pass the message)

Thank you

Last edited by Dreamer : 08-11-2007 at 07:03 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-11-2007, 03:33 AM
matias.quaglia's Avatar
Junior Member
 
Join Date: Aug 2007
Posts: 18
Default

Hi there!

I'm a beginner too.
I think you made a very interesting question.
I mean that in the hipotetic example you gave (a entry in a blog identified by an ID parameter passed in the url), I would keep the handling of a missing or non-existent ID in the controller. Validate the parameters is part of the business logic. I think an errorController is right when something wrong that scapes from the business logic happens (ie: the database server doesn't respond).

Cheers,

Q
__________________
Matías Quaglia
==========
http://www.matiasquaglia.com.ar
Credo est Creo
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-14-2007, 09:50 PM
Elemental's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 122
Default

I'm currently working on the error reporting for my companies internal CMS. There is definately a lack of resources for how to handle this critical portion of our apps out there right now. The Zend documentation is nill and tutorials are almost non-existant. Hopefully something will spring up soon. As it is, its a matter of trial and error to find a nice elegant solution. Anyone know of any good ZF Error Handling resources?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-06-2008, 01:28 PM
Junior Member
 
Join Date: Mar 2008
Posts: 1
Default

I think too it would be great that someone gives idea or best practice to manage error with Zend Framework.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-06-2008, 05:18 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Lightbulb

You can use the normal try/catch/throw blocks that you would normally use in any other PHP app. Refer to the PHP manual on that: PHP: Exceptions - Manual

You can just do something like this:

PHP Code:
try {
    
// the code I'm trying to run
} catch (Exception $e) {
   
// do something with the error
   
echo $e->getMessage();
  
// Consider using Zend_Log to log the error

The framework has extended the PHP Exceptions, with Zend_Exception, which is explained briefly here: Zend Framework: Manual: Zend_Exception

So you can use Zend_Exception instead of Exception in the above code. Also be aware that some of the components extend Zend_Exception and may have another Exception object you can use too. Depends on the circumstances.

You can also throw your own errors in ZF. Using the missing id for the db record example, you can just do something like this:

PHP Code:
if(!isset($id)) {
    
$e = new Exception;
    throw 
$e;

You'll still need to catch the error you throw, but this should get you started.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-06-2008, 06:56 PM
Junior Member
 
Join Date: Feb 2008
Posts: 18
Default

Also take a look on Zend_Controller_Plugin_ErrorHandler

Haven't checked myself but it should be useful for wrong controllers/models/action

I'm still looking myself... remember to read ApiDoc, got some interesting things off it
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:53 PM.