[prev in list] [next in list] [prev in thread] [next in thread] 

List:       spacewalk-devel
Subject:    [Spacewalk-devel] global exception handler in Struts
From:       jesusr () redhat ! com (Jesus Rodriguez)
Date:       2009-03-26 2:05:16
Message-ID: 20090326020516.GA29174 () transam ! devel ! redhat ! com
[Download RAW message or body]

We use the global exception handler in Struts today for
PermissionException, LookupException, etc. This is a great way of
sending users to an error page and keep the struts-config a bit
cleaner. It also keeps your action cleaner.

For example, say you want to send a user to an error page (this
is different than an error message at the top of a page), instead
of doing this:


public class SomeAction {
   ...
   try {
      // do something
   } catch (Exception e) {
      log.error("message", e);
      return mapping.findForward("error");
   }

}

You can simply do this:

public class SomeAction {
   ...
   try {
      // do something
   } catch (Exception e) {
      throw new SomeMappedException();
   }
}

You can reuse this SomeMappedException in other actions like
we do with the PermissionException today.

-- 
jesus m. rodriguez        | jesusr at redhat.com
sr. software engineer     | irc: zeus
rhn satellite & spacewalk | 919.754.4413 (w)
rhce # 805008586930012    | 919.623.0080 (c)
+-------------------------------------------+
|  "Those who cannot learn from history     |
|   are doomed to repeat it."               |
|                       -- George Santayana |
+-------------------------------------------+



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic