aspose file tools*
The moose likes Servlets and the fly likes Exception Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Exception Handling" Watch "Exception Handling" New topic
Author

Exception Handling

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
I have made a simple client server application wherein I am accepting a username and password from client and server checks whether it is a proper user or not.
Problem is when the client presses its submit button and when the request is sent to the server client again presses the stop button in the browser. In such a situation I get a SocketException at the server side. I am using simple html for client and servletrunner as server.
help me out if you have a suggesstion
thanx
nitin
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Since it is the client closing the socket, there is not a whole lot you can do about it except catch the exception. I generally try to enclose as much code as possible in doGet and doPost in a giant try - catch structure -
You could have a chain of catch statements to isolate the various sorts that might be thrown.
}catch( SocketException se ){
}catch( IOException ioe ){
}catch( Exception ex ){
}
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
"I generally try to enclose as much code as possible in doGet and doPost in a giant try - catch structure..."
I hear you
Except for the "giant" part
I try to keep my methods 20-30 lines long maximum. If a method cannot fit in a screen it's a signal that I should make it smaller as in separating it into logical functions.


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
I interpreted Bill's 'giant' word's meaning according to the cotext. Since all routing takes place from doGet(..) or doPost(..) methods if we try to put all the code in doGet(..) or doPost(..) inside a try...catch block , what it really means is it captures any exception whatsoever generated by the following methods like that. The code inside a goGet(..) may be just one line. But it's value is huge. So surrounding that one line with a try catch really means it is a 'GIANT CATCH'. The words serves it purpose in this context. This is how I thought when I read Bill's post.
regds
maha anna
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception Handling