Top level exception catch
843844Jan 3 2008 — edited Jan 25 2008I've seen a few discussion on this topic but haven't seen a clear answer so please permit me to clarify the issue.
Our exception handling policy basically says to throw a RuntimeException in the case of a true system error and let that propagate up the call stack to a single point where it will be caught and handled. Intermediate code should not catch these exceptions. This way we make sure no uncaught exceptions are allowed to leak out of the application and all system errors are handled robustly and consistently. This seems like a very common error handling strategy in the Java web world.
So where can I put that single, top-most exception catch in JSF 1.2 (we're using Facelets not JSP)?
So far I only see two main candidate solutions:
1) Extend the Faces servlet to include a catch clause in the service method
(but this wouldn't catch startup errors that occur before the Faces servlet
is invoked)
2) Create a Servlet Filter, mapped to a univeral URL, that includes a catch
in its doChain method
I see Servlet Filters are poo-pooed as old school these days but it seems they are the only way to provide a single place that can truly catch all exceptions that occur anywhere throughout the entire request life-cycle.
Are there any other options?