A couple of questions regarding Exception handeling.

javadevmtl java.dev.mtl at gmail.com
Tue May 18 23:46:02 EDT 2010


Hi using the latest 3.1.5 GA

Question 1: Is there a way to catch exceptions in one handler instead of
various? Or control it better?

pipeline.addLast("timeout", new ReadTimeoutHandler(...)); <--- ReadTimeout
gets caught in my handler
pipeline.addLast("framer", new MyFrameDecoder(...));
pipeline.addLast("stringdecoder", stringDecoder);
pipeline.addLast("stringencoder", stringEncoder);
pipeline.addLast("logs", loggingHandler);
pipeline.addLast("threaded", executionHandler);
pipeline.addLast("encoderdecoder", new MyEncoderDecoder(...)); <--
Exceptions get caught in MyFrameDecoder
pipeline.addLast("handler", new MyDHandler(...));

Question 2: Is it advisable to be able to write back to the channel in an
exception? Or should you just always close the channel? And if you could how
do you do so? Bassically on different types of exception I want to take
appropriate action and maybe reply back to the client.

Question 3: To avoid ClosedChannelException is it sufficient enough in my
handler to do...

public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
throws Exception {
		
	Channel ch = e.getChannel();

	if(ch.isConnected)
	{
		ChannelFutur cf = ch.write(.....);
		cf.addListener(...CLOSE)
	}


Question 4: Is there a way to control the ReadTimeoutException? Meaning...
Each client which connects is expected to only send one and only one
"message" to the server and wait for the server response. If the client has
successfully sent the "message" I do not want the server to throw a
ReadTimeoutException.

For instance client connects and sends request to the server. The server
begins to process the request but takes a bit longer then the read time out
value. Netty throws ReadTimeoutException (Which I catch and close the
connection. Only want to do this if the client hasn't succesfully made a
proper request). So now the client is disconnected because of this and never
gets back the result. At this point also a ClosedSocketException is caught
because obviously the server tried to write to a closed socket.

Maybe my understanding of ReadTimeout is wrong. The only reason why I even
want to implement a ReadTimeout handler is because I want to make sure that
the client doesn't fudge up the message sending and hangs for ever. But if
the client has done everything correctly to not throw a ReadTimeoutException
and to close the socket the moment the server is ready to send back the
reply. Does it make sense?


Thanks in advance
-- 
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/A-couple-of-questions-regarding-Exception-handeling-tp5073212p5073212.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list