You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Grzegorz Stasica <gs...@poczta.onet.pl> on 2005/04/26 19:48:44 UTC

throw exception in servlet filter - no error page displayed

hi,

My doFilter method looks like that:
     public void doFilter(ServletRequest arg0, ServletResponse arg1,
             FilterChain arg2) throws IOException, ServletException {
         arg2.doFilter(arg0,arg1);
         try{
             HibernateSessionFactory.commitTransaction();
             System.out.println("koniec");
         }catch(DAOException e){
             throw new ServletException(e);
         }finally{
             HibernateSessionFactory.closeSession();
         }
     }

My problem is that although DAOException is being catched and new 
ServletException is being thrown the page is already rendered. There is 
no error on the page and the only place where I can find that something 
went wrong is server log. What is wrong? Why ServletException doesn't 
affect page?


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: throw exception in servlet filter - no error page displayed

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
On 26/04/05 18:48&nbsp;Grzegorz Stasica wrote:
> My doFilter method looks like that:
>     public void doFilter(ServletRequest arg0, ServletResponse arg1,
>             FilterChain arg2) throws IOException, ServletException {
>         arg2.doFilter(arg0,arg1);
>         try{
>             HibernateSessionFactory.commitTransaction();
>             System.out.println("koniec");
>         }catch(DAOException e){
>             throw new ServletException(e);
>         }finally{
>             HibernateSessionFactory.closeSession();
>         }
>     }
> 
> My problem is that although DAOException is being catched and new 
> ServletException is being thrown the page is already rendered. There is 
> no error on the page and the only place where I can find that something 
> went wrong is server log. What is wrong? Why ServletException doesn't 
> affect page?

Did you mean to send this to the tomcat-user list? I think you're more 
likely to get a good technical answer there. Firstly I'd check that 
you're actually going thro the filter where you think you are. Secondly 
I'd check the servlet spec to see what is actually meant to happen when 
a filter throws an exception.

Presumably you never see the 'koniec' output?

Perhaps hibernate throws a different exception that your not catching.

Also your call to arg2.doFilter might actually commit the response 
before the exception, allowing no chance for the exception to affect the 
response.

HTH
Adam

-- 
struts 1.2 + tomcat 5.0.19 + java 1.4.2
Linux 2.4.20 Debian

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org