17 marzo 2010

Unified error page and exception handling

Unified error page and exception handling


A web application can run into a server-side error for many different reasons and at any point in time. Finding the right strategy for your application, how to deal with these error conditions and exceptional situations, can be difficult. This page provides some guidelines and a simple but effective solution.

When a client request is handled by a web application server, exceptions can be thrown by code at any time. Typically, you need to consider:

  • Exceptions thrown by the web application server, usually the servlet container. For example, exceptions you definitely have to expect and handle include session limit violations. If your servlet container reaches its configured maximum active session limit, your users should be presented with a nice error message that tells them to come back later.
  • Exceptions can be thrown by the web application frameworks and 3rd party libraries you are using. In a Seam application, those frameworks would typically include JSF, Facelets, Hibernate, and of course Seam and any of its integration modules. There are many exceptions that are obvioulsy related to bugs in your application, for these you might want to encourage the users to report these with a nice message. But you also have other exceptions, such as database lock acquisition failures, that indicate an overloaded system, which does not necessarily require a bug report.
  • Finally, you have your own error handling in your web application. You use (runtime) infrastructure exceptions to indicate fatal error conditions which should be reported by users when they encounter them. You use (checked) application exceptions that are expected and are handled in your code, probably without even letting the users know that some exceptional application flow occurred behind the scenes.

Handling recoverable exceptions

Seam comes with an exception handling servlet filter that wraps its processing of a request:

(... seguir leyendo en el sitio original)

No hay comentarios: