nbubna      2003/10/01 17:13:11

  Modified:    src/java/org/apache/velocity/tools/view/servlet
                        VelocityViewServlet.java
  Log:
  improve error handling
  
  Revision  Changes    Path
  1.15      +37 -23    
jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java
  
  Index: VelocityViewServlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity-tools/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- VelocityViewServlet.java  1 Oct 2003 23:46:45 -0000       1.14
  +++ VelocityViewServlet.java  2 Oct 2003 00:13:11 -0000       1.15
  @@ -425,6 +425,9 @@
           }
           catch (Exception e)
           {
  +            // log the exception
  +            Velocity.error("Exception processing the template: "+e);
  +
               // call the error handler to let the derived class
               // do something useful with this failure.
               error(request, response, e);
  @@ -637,29 +640,40 @@
       protected void error(HttpServletRequest request, 
                            HttpServletResponse response, 
                            Exception cause)
  -        throws ServletException, IOException
  +        throws ServletException
       {
  -        StringBuffer html = new StringBuffer();
  -        html.append("<html>");
  -        html.append("<title>Error</title>");
  -        html.append("<body bgcolor=\"#ffffff\">");
  -        html.append("<h2>VelocityViewServlet : Error processing the template</h2>");
  -        html.append("<pre>");
  -        String why = cause.getMessage();
  -        if (why != null && why.trim().length() > 0)
  -        {
  -            html.append(why);
  -            html.append("<br>");
  -        }
  -
  -        StringWriter sw = new StringWriter();
  -        cause.printStackTrace(new PrintWriter(sw));
  -
  -        html.append(sw.toString());
  -        html.append("</pre>");
  -        html.append("</body>");
  -        html.append("</html>");
  -        response.getOutputStream().print(html.toString());
  +        try
  +        {
  +            StringBuffer html = new StringBuffer();
  +            html.append("<html>");
  +            html.append("<title>Error</title>");
  +            html.append("<body bgcolor=\"#ffffff\">");
  +            html.append("<h2>VelocityViewServlet : Error processing the 
template</h2>");
  +            html.append("<pre>");
  +            String why = cause.getMessage();
  +            if (why != null && why.trim().length() > 0)
  +            {
  +                html.append(why);
  +                html.append("<br>");
  +            }
  +
  +            StringWriter sw = new StringWriter();
  +            cause.printStackTrace(new PrintWriter(sw));
  +
  +            html.append(sw.toString());
  +            html.append("</pre>");
  +            html.append("</body>");
  +            html.append("</html>");
  +            response.getOutputStream().print(html.toString());
  +        }
  +        catch (Exception e)
  +        {
  +            // clearly something is quite wrong.
  +            // let's log the new exception then give up and
  +            // throw a servlet exception that wraps the first one
  +            Velocity.error("Exception while printing error screen: "+e);
  +            throw new ServletException(cause);
  +        }
       }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to