• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Handling

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic