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

(version: Netty 4.0.4.Final)

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

There is only one way to handle an outgoing exception by analyzing the future result as follows:

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

But it is very inconvenient.

+7
exception-handling netty
source share
1 answer

This is by design ... Outbound operations are only notified through the Future, because otherwise we will need to do double notifications that have some performance limitation. If you want it to be propagated to the exceptionCaught handler, you can simply add ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE as a Listener to the returned ChannelFuture.

+10
source share

All Articles