-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stan,

Stanislav wrote:
> I'm using Strus and this is my problem. I have this method A which
> have input and outpur parameters. There is try/catch block in method
> A that capture Exceptions. I want to redirect or forward to jsp page
> B from method A when some error is happend and NOT to return to class
> C from which method A is invoked. Is this possible to achieve?

The best way to direct Struts to another location is to return the
appropriate ActionForward from your Action's execute() method.

Since you are using another method ("method A") to do your work, this is
not possible directly (that is, you cannot "return" a value from "method
A" and have it skip further processing in your action class). This just
isn't now Java (or any other programming language, really) works.

What you /can/ do is let the exception from "method A" propagate all the
way back up into your action code, and catch it /there/ instead. Like this:

public ActionForward execute(...) throws Exception
{
   .
   .
   .
   try {
     .
     .
     methodA();
     .
     .
     .
   } catch (SomeException e)
   {
      return mapping.findForward("method-a-error");
   }
}

If it is inappropriate to allow SomeException to propagate from "method
A" back into the action code, then consider wrapping that exception in
something else, like MethodAException:

public void methodA(...)
{
   .
   .
   .
   catch(SomeException e) {
     throw new MethodAException("Method A failed", e);
   }
}

and in your action code, catch MethodAException instead of SomeException.

Don't forget that your Action is really the place where decisions about
control flow need to be made... helper methods can accomplish other
tasks of help the Action make decisions, but ultimately, it's the
Action's responsibility to control the flow.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFgq449CaO5/Lv0PARAnDtAKC1rPl0ZmvCW3EnqrAW/qxq+wrQ0gCfWJgi
ra0kGCKdGxz7BZASiiTZmOY=
=Fp9O
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to