Hi, Yes it is a good idea to create your own exception class !
A little link, worth reading, about exceptions http://ralphschindler.com/2010/09/15/exception-best-practices-in-php-5-3 <http://ralphschindler.com/2010/09/15/exception-best-practices-in-php-5-3>:) No there's no symfony way about exceptions, it uses the language features, as usual. Regards, Before Printing, Think about Your Environmental Responsibility! Avant d'Imprimer, Pensez à Votre Responsabilitée Environnementale! On Mon, Jan 10, 2011 at 4:18 PM, Gabriel Comeau <[email protected]>wrote: > Hello all, > > I'm having a problem using a redirect inside of my action code. The > problem is that the redirect occurs inside of a try block. Before it > happens, there is a method call to an object from my model. If this > object is not in the right state when the method is called, it throws > an exception. > > The action code looks like this: > > try > { > $this->purchaseOrder->doPurchase(); > $this-redirect('thanks'); > } > catch (Exception $e) > { > $this->getUser()->setFlash('error', 'Sorry - '.$e->getMessage()); > $this->redirect('homepage'); > } > > If the doPurchase() method actually throws an exception, this code > works exactly as expected. The problem when the method completes its > execution without problem. > > The redirect to the 'thanks' action happens, but the flash error gets > displayed (only the "Sorry - " part). I figured out that this is > because a redirect throws an sfStopException, which doesn't have a > message (hence the $e->getMessage() not printing anything out). > > The solution I am thinking of right now is to create a custom > exception class for my model so that my catch block can instead be > something like catch (purchaseOrderException $e) and will ignore the > stopException. > > Is this the right way to go about it or is there a better solution to > this problem that I'm not seeing. > > This is my first real symfony project, though I've been working with > PHP for a while. If there's a framework-specific way of solving this > problem, I'd love to know about it. > > Thanks very much, > > Gabriel > > -- > If you want to report a vulnerability issue on symfony, please send it to > security at symfony-project.com > > You received this message because you are subscribed to the Google > Groups "symfony users" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<symfony-users%[email protected]> > For more options, visit this group at > http://groups.google.com/group/symfony-users?hl=en > -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en
