you may surround your java code by a try catch and in the catch block do:
FacesContext.getCurrentInstance().getExternalContext().redirect("foo.xhtml");
Id this doesn't answe your question you may want to give more code, and try to explain better your problem