(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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With