Hi Adile,

On 21 Jul 2005 at 19:09, Adile Abbadi wrote:

> Now I did a little more experimenting and discovered something interesting -
> as I said I can get an exception to be thrown to the page in a simple JSP
> file (I made it do a null pointer for example) and I can get it do pretty
> any other exception as well. Now what I did is I took one my more
> complicated JSP pages, made a copy and made a few changes to force some
> exceptions - now here is the weird thing - some exceptions are thrown to the
> screen and some are not.
> 
> For example I had a ResultSet DB object and I made a syntax error and I got
> an Error 500 screen to come up as follows (note I took out the extra stuff
> to shorten the email)
> 
> org.apache.jasper.JasperException: Unable to compile class for JSP

Note, you will always get a stacktrace if Tomcat can't compile a JSP - I 
believe this is appropriate as this is a "developer" error rather than a 
"runtime" error.

> However I tried to get it to do a syntax error in the query - and I end up
> with a blank page. The catalina log shows nothing, but my context log shows
> the following (clown is the word I used to screw up the query)
> 
> javax.servlet.ServletException: ERROR:  syntax error at or near "CLOWN" at
> character 260
> 
> --Root Cause--
> java.sql.SQLException: ERROR:  syntax error at or near "CLOWN" at character
> 260
> 
> Its almost as it the page refuses to compile with this error.

No, it has compiled OK or else you'd get the same kind of message as you 
did previously.

I suspect the reason you get a blank page is that for reason's I've never 
been able to discover, SQL Exceptions are nested and the last error (the 
one shown on your error page) is always empty :-(

to see the true error(s), you have to write some code that works its way 
back through the nested SQL Exceptions, printing out the message for each 
as you go.

Something like the following (untested) in your error.jsp should do the trick:

<%
  if (exception == null) {
%>
    <H1>A null exception was encountered</H1>
<%
  } else {
    if (exception instanceof SQLException) {
      Exception e = exception;
      while (e != null) {
%>
        <P>Error Code: <%=e.getErrorCode()%></P>
        <P>Message: <%=e.getMessage()%></P>
<%
        e = e.getNextException();
      }
    } else {
      // non-sql error handling here...
    }
  }

HTH,

Rob Hills
www.netpaver.com.au
Western Australia

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

Reply via email to