aspose file tools*
The moose likes Servlets and the fly likes Exception doesn't always cause flow to errorPage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Exception doesn Watch "Exception doesn New topic
Author

Exception doesn't always cause flow to errorPage

Rob Chadwick
Greenhorn

Joined: Mar 02, 2001
Posts: 7
I am modifying a JSP (running on WebLogic Server 4.51).
I was making changes to add an errorPage (in the hope of making
debugging easier) and I tested it by adding a line of code that
would cause a DivideByZero exception:
<% int xyz = 1/0; %>
Sure enough, the error page displayed! So far, so good.
However, I found that if I moved the statement that causes the exception lower down in the document I wasn't getting an errorPage.
All I get is a partial document (HTML below the statement isn't
being processed).
I guess I need to look at the generated servlet code to work out why it's not forwarding to the errorPage, but I was wondering if
any one else had come across this problem and worked out the cause.

maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Rob,
Did you put those errorPage and isErrorPage attributes in your main.jsp and errorPage.jsp properly?
Please have a look at this example. http://www.javaranch.com/ubb/Forum7/HTML/002845.html
Just take this code and insert your divide By Zero code inside body tags and check.
regds
maha anna
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Rob Chadwick:
However, I found that if I moved the statement that causes the exception lower down in the document I wasn't getting an errorPage.
All I get is a partial document (HTML below the statement isn't
being processed).

The problem is that the response has already been committed. The servlet engine uses an output buffer, which is 8KB by default. As soon as it is full, the first chunk of the HTTP response is sent to the client, including the HTTP header. Once the response has been committed in this way, the client simply cannot be redirected to the error page anymore.
That is what you are seeing: as you move your erroneous code down, you go past the point where the response is being committed. The exception thrown will prevent the remainder of the JSP from executing, so you end up with half a page.
There are two things you can do. The first and easiest is to increase the response buffer size (<%@page buffer="16kb"%> ). But, generally, you should try to do all the important processing before you start generating content in earnest.
- Peter
Rob Chadwick
Greenhorn

Joined: Mar 02, 2001
Posts: 7
Peter,
thanks for your reply.
I increased the buffer size and I did get redirected to the error page.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception doesn't always cause flow to errorPage