Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why ChannelOutboundHandler exceptions not caught by exceptionCaught() method? (Netty 4.0.4.Final)

(version: Netty 4.0.4.Final)

If an exception rises in ChannelInboundHandler, I can handle it in exceptionCaught() method but if the exception rises in ChannelOutboundHandler, I can't. Because, exceptionCaught() is not a call. Why is this so?

There is only way to handle outbound exception by analize Future result like this:

channel.writeAndFlush(serverPacket).addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (!future.isSuccess()) {
                future.cause().printStackTrace();
            }
        }
});

But it is very inconveniently.

like image 689
Megaprog Avatar asked Jul 26 '13 09:07

Megaprog


1 Answers

It's by design... Outbound operations only are notified via the Future as otherwise we would need to do double notifications which has some performance penalty. If you want to to have it propagated to the exceptionCaught handler you can just add the ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE as Listener to the returned ChannelFuture.

like image 106
Norman Maurer Avatar answered Oct 21 '22 15:10

Norman Maurer