I have another problem with handling exceptions in jsf / richfaces.
I have wrapper for FacesServlet to handling exceptions, but it catch only some exceptions, why ??
For example java.net.SocketException (connection to db) haven't be caught.
Another problem is that FacesContext context = FacesContext.getCurrentInstance(); return null in catch...
Is a way to get context and add Faces Message... ?
package test;
 
 
import java.io.IOException;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.webapp.FacesServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
 
 
/**
 * Wrapper 
 * 
 * @author marioosh
 * 
 */
public class FacesServletWrapper extends HttpServlet {
 private Logger log = Logger.getLogger(getClass());
 private FacesServlet facesServlet;
 
 
 
public void init(ServletConfig servletConfig) throws ServletException {
 log.debug("INIT");
 
 
 
facesServlet = new FacesServlet();
 facesServlet.init(servletConfig);
 
 
 
System.getProperties().put("org.apache.el.parser.COERCE_TO_ZERO", "false");
 }
 
 
 
public void destroy() {
 facesServlet.destroy();
 }
 
 
 
public ServletConfig getServletConfig() {
 return facesServlet.getServletConfig();
 }
 
 
 
public String getServletInfo() {
 return facesServlet.getServletInfo();
 }
 
 
 
public void service(ServletRequest request, ServletResponse response)
 throws ServletException, IOException {
 try {
 facesServlet.service(request, response);
 } catch (Throwable e) {
 log.debug("FacesServletWrapper - error captured!");
 
 
 
FacesContext context = FacesContext.getCurrentInstance(); /// <---- null :((
 context.addMessage(FacesMessage.FACES_MESSAGES, new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), e.toString()));
 
 
}
 }
 
 
 
}