Creating your own exception class is the best way, but I'd still like
to add this alternative: using multiple catch bocks after a try:
try {
//your stuff
}
catch (sfStopException $e) {
throw $e; //rethrowing it, nothing else to do
}
catch (Exception $e) {
//handle error
}
On Mon, Jan 10, 2011 at 16:18, 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]
> 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